Struggeling with collections

2016-03-07 Thread Faling Dutchman
Hey folks, I am just starting off in python, but have good knowledge of both Java and C#. Now is the problem that I need to have multiple instances of one dictionary, that is not a problem if you know how many, but now, it is an unknown amount. Some background info: I am making a library for a

Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-07 Thread Steven D'Aprano
On Monday 07 March 2016 17:13, Veek. M wrote: > import foo > class Bar(object): > def __del__(self, foo=foo): > foo.bar()# Use something in module foo > > ### Why the foo=foo? import foo, would increment the ref-count for > object 'foo' Yes. And then at shutdown, the module globals

Re: Struggeling with collections

2016-03-07 Thread Vincent Vande Vyvre
Le 07/03/2016 09:24, Faling Dutchman a écrit : Hey folks, I am just starting off in python, but have good knowledge of both Java and C#. Now is the problem that I need to have multiple instances of one dictionary, that is not a problem if you know how many, but now, it is an unknown amount. S

How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread ZhangXiang
In python3, when I write code like this: try: fields = [getattr(Product, field) for field in fields.split(',')] except AttributeError as e: raise HTTPError(...) I want to raise a new type of error giving a string telling the user which attribute is not valid. But I don't see any method I

Re: Struggeling with collections

2016-03-07 Thread Steven D'Aprano
On Monday 07 March 2016 19:24, Faling Dutchman wrote: > Hey folks, > > I am just starting off in python, but have good knowledge of both Java and > C#. Now is the problem that I need to have multiple instances of one > dictionary, that is not a problem if you know how many, but now, it is an > un

Re: Struggeling with collections

2016-03-07 Thread Faling Dutchman
Op maandag 7 maart 2016 09:49:51 UTC+1 schreef Vincent Vande Vyvre: > Le 07/03/2016 09:24, Faling Dutchman a écrit : > > Hey folks, > > I am just starting off in python, but have good knowledge of both Java and > > C#. Now is the problem that I need to have multiple instances of one > > dictionar

Re: Struggeling with collections

2016-03-07 Thread Gary Herron
On 03/07/2016 12:24 AM, Faling Dutchman wrote: Hey folks, I am just starting off in python, but have good knowledge of both Java and C#. Now is the problem that I need to have multiple instances of one dictionary, that is not a problem if you know how many, but now, it is an unknown amount. S

Re: Struggeling with collections

2016-03-07 Thread Jussi Piitulainen
Faling Dutchman writes: > I am just starting off in python, but have good knowledge of both Java > and C#. Now is the problem that I need to have multiple instances of ... > it prints: <__main__.Item object at 0x02EBF3B0> > > So that is not usefull to me. There can be an infinite amount of ...

Re: Struggeling with collections

2016-03-07 Thread Faling Dutchman
Op maandag 7 maart 2016 10:31:48 UTC+1 schreef Jussi Piitulainen: > Faling Dutchman writes: > > I am just starting off in python, but have good knowledge of both Java > > and C#. Now is the problem that I need to have multiple instances of > ... > > it prints: <__main__.Item object at 0x02EBF3B0> >

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread Peter Otten
ZhangXiang wrote: > In python3, when I write code like this: > > try: > fields = [getattr(Product, field) for field in fields.split(',')] > except AttributeError as e: > raise HTTPError(...) > > I want to raise a new type of error giving a string telling the user which > attribute is not

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread Xiang Zhang
On Monday, March 7, 2016 at 5:49:48 PM UTC+8, Peter Otten wrote: > ZhangXiang wrote: > > > In python3, when I write code like this: > > > > try: > > fields = [getattr(Product, field) for field in fields.split(',')] > > except AttributeError as e: > > raise HTTPError(...) > > > > I want t

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Tony van der Hoff
On 06/03/16 14:41, Steven D'Aprano wrote: On Sun, 6 Mar 2016 10:34 pm, Tony van der Hoff wrote: Hi, I've been experimenting with a short test program under python 2.7 and python 3.4.2. It's a simple read from file, and locate a word therein. I get the (subjective) impression that python2 is s

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread jmp
On 03/07/2016 09:46 AM, ZhangXiang wrote: In python3, when I write code like this: try: fields = [getattr(Product, field) for field in fields.split(',')] except AttributeError as e: raise HTTPError(...) I want to raise a new type of error giving a string telling the user which attrib

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 06/03/2016 11:34, Tony van der Hoff wrote: Hi, I've been experimenting with a short test program under python 2.7 and python 3.4.2. It's a simple read from file, and locate a word therein. I get the (subjective) impression that python2 is slightly faster than python3. Is that correct? Is the

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Marko Rauhamaa
BartC : > I've also found that 3 was consistently slower than 2 on various > benchmarks. Perhaps 10 to 20% slower (also 3.4 vs. 2.7). Python doesn't exist for performance-critical parts of your solution. Also, Python programs tend to take huge amounts of space. Where that is a problem, use some

Re: __del__: when to use it? What happens when you SystemExit/NameError wrt del? Method vs function calls.

2016-03-07 Thread Veek. M
Steven D'Aprano wrote: > On Monday 07 March 2016 17:13, Veek. M wrote: > >> import foo >> class Bar(object): >> def __del__(self, foo=foo): >> foo.bar()# Use something in module foo >> >> ### Why the foo=foo? import foo, would increment the ref-count for >> object 'foo' > > Yes. And

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 07/03/2016 11:11, Marko Rauhamaa wrote: BartC : I've also found that 3 was consistently slower than 2 on various benchmarks. Perhaps 10 to 20% slower (also 3.4 vs. 2.7). Python doesn't exist for performance-critical parts of your solution. Also, Python programs tend to take huge amounts of

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Andrew Jaffe
On 06/03/2016 14:41, Steven D'Aprano wrote: On Sun, 6 Mar 2016 10:34 pm, Tony van der Hoff wrote: Hi, I've been experimenting with a short test program under python 2.7 and python 3.4.2. It's a simple read from file, and locate a word therein. I get the (subjective) impression that python2 is

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Fabien
On 03/07/2016 12:38 PM, BartC wrote: (Although competing with CPython is too easy. PyPy is more of a problem. With the Jpeg benchmark I mentioned, I can beat PyPy up to 6Mpix, but then PyPy starts to get faster. At 80Mpix, PyPy is 60% faster.) Just out of curiosity: are you also competing agai

Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-07 Thread Veek. M
import socket class Client(object): def __init__(self,addr): self.server_addr = addr self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) self.sock.connect(addr) def __getstate__(self): return self.server_addr def __setstate__(self,value): self.server_addr = value self.s

Re: Regex: Perl to Python

2016-03-07 Thread Fillmore
Big thank you to everyone who offered their help! On 03/06/2016 11:38 PM, Fillmore wrote: -- https://mail.python.org/mailman/listinfo/python-list

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 07/03/2016 12:19, Fabien wrote: On 03/07/2016 12:38 PM, BartC wrote: (Although competing with CPython is too easy. PyPy is more of a problem. With the Jpeg benchmark I mentioned, I can beat PyPy up to 6Mpix, but then PyPy starts to get faster. At 80Mpix, PyPy is 60% faster.) Just out of cu

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 12:25 AM, BartC wrote: > No, I only compare basic language functions. I understand that Python > depends on complex built-in functions, and external libraries such as numpy, > for it to be used viably. But I'm also interested in using such languages > directly. > > Take the

importing

2016-03-07 Thread Tony van der Hoff
I thought I understood this, but apparently not: Under py3: 1. "import tkinter" imports the whole module into the name space. Any access to names therein must be prefixed with the module name. ie top = tkinter.Tk() But tkinter.messagebox.showwarning() errors with "module has no attribute 'mes

Re: importing

2016-03-07 Thread Tim Golden
On 07/03/2016 15:54, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any > access to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.messagebox.

Re: importing

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 8:54 AM, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any access > to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.

ANN: eGenix pyOpenSSL Distribution 0.13.14

2016-03-07 Thread eGenix Team: M.-A. Lemburg
ANNOUNCING eGenix.com pyOpenSSL Distribution Version 0.13.14 An easy-to-install and easy-to-use distribution of the pyOpenSSL Python interface for OpenS

Re: importing

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 2:54 AM, Tony van der Hoff wrote: > I thought I understood this, but apparently not: > Under py3: > > 1. "import tkinter" imports the whole module into the name space. Any access > to names therein must be prefixed with the module name. > ie top = tkinter.Tk() > But tkinter.

Re: A mistake which almost went me mad

2016-03-07 Thread Ian Kelly
On Thu, Mar 3, 2016 at 11:50 AM, Tim Chase wrote: > I think that relative imports should ameliorate this, as I usually > hit it when I'm using smtplib which in turn imports "email" (and, in > 2.x when it found my local email.py would crash and burn). If it used > a relative import that forced it t

Re: A mistake which almost went me mad

2016-03-07 Thread Random832
On Mon, Mar 7, 2016, at 11:19, Ian Kelly wrote: > Relative imports only work inside packages. You can't use a relative > import to import one top-level module from another. > > Besides, the relative import doesn't help to disambiguate in this > case. The absolute path of the stdlib email module is

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 15:54, Tony van der Hoff wrote: I thought I understood this, but apparently not: Under py3: 1. "import tkinter" imports the whole module into the name space. Any access to names therein must be prefixed with the module name. ie top = tkinter.Tk() But tkinter.messagebox.showwarning(

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread Xiang Zhang
Hi, I know I can get the attribute name in some way, but since I just want the attribute name when an AttributeError caused by it raised, I really don't want to inspect the string or introduce one more layer over getattr. I hope I can get the attribute which causes the exception from the Attrib

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread Tim Golden
On 07/03/2016 16:25, Xiang Zhang wrote: > Hi, > > I know I can get the attribute name in some way, but since I just > want the attribute name when an AttributeError caused by it raised, I > really don't want to inspect the string or introduce one more layer > over getattr. I hope I can get the att

Re: A mistake which almost went me mad

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 3:19 AM, Ian Kelly wrote: > On Thu, Mar 3, 2016 at 11:50 AM, Tim Chase > wrote: >> I think that relative imports should ameliorate this, as I usually >> hit it when I'm using smtplib which in turn imports "email" (and, in >> 2.x when it found my local email.py would crash a

Question

2016-03-07 Thread Ben Morales
I am trying to download Python but I have windows 10 and I do not see a 64 bit download for my operating system. Do you have a 64 bit for windows? Sincerely, *Ben Morales* -- https://mail.python.org/mailman/listinfo/python-list

Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: > I am trying to download Python but I have windows 10 and I do not see a 64 > bit download for my operating system. Do you have a 64 bit for windows? What page are you looking at? https://www.python.org/downloads/release/python-351/ has download

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread Xiang Zhang
On Tuesday, March 8, 2016 at 12:38:31 AM UTC+8, Tim Golden wrote: > On 07/03/2016 16:25, Xiang Zhang wrote: > > Hi, > > > > I know I can get the attribute name in some way, but since I just > > want the attribute name when an AttributeError caused by it raised, I > > really don't want to inspect t

Re: importing

2016-03-07 Thread Tony van der Hoff
Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tell you what you need to import to make something work. In this case, I would guess that "import tkinter.messagebox" or "from tkinter import message

Re: Question

2016-03-07 Thread Mark Lawrence
On 07/03/2016 16:57, Ian Kelly wrote: On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: I am trying to download Python but I have windows 10 and I do not see a 64 bit download for my operating system. Do you have a 64 bit for windows? What page are you looking at? https://www.python.org/down

Re: How to get which attribute causes the AttributeError except inspecting strings?

2016-03-07 Thread Mark Lawrence
On 07/03/2016 16:38, Tim Golden wrote: On 07/03/2016 16:25, Xiang Zhang wrote: Hi, I know I can get the attribute name in some way, but since I just want the attribute name when an AttributeError caused by it raised, I really don't want to inspect the string or introduce one more layer over get

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 17:23, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tell you what you need to import to make something work. In this case, I would guess that "import tkint

Re: importing

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: > Thanks to all who replied to my cry for help; I understand it better now. > But: > > On 07/03/16 16:08, Chris Angelico wrote: >> >> >> The documentation should tell you what you need to import to make >> something work. In this case, I wou

Re: importing

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 10:23 AM, Tony van der Hoff wrote: > However, more generally, how am I supposed to know that a module is part of > a package, and needs a "magic" stanza to get a module loaded? If the import path of the module has a dot in it, then it's part of a package. -- https://mail.p

Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 10:25 AM, Mark Lawrence wrote: > On 07/03/2016 16:57, Ian Kelly wrote: >> >> On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales >> wrote: >>> >>> I am trying to download Python but I have windows 10 and I do not see a >>> 64 >>> bit download for my operating system. Do you have a

Re: Question

2016-03-07 Thread Jon Ribbens
On 2016-03-07, Ian Kelly wrote: > On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: >> I am trying to download Python but I have windows 10 and I do not see a 64 >> bit download for my operating system. Do you have a 64 bit for windows? > > What page are you looking at? > https://www.python.org/

Re: Question

2016-03-07 Thread Jon Ribbens
On 2016-03-07, Ian Kelly wrote: > On Mon, Mar 7, 2016 at 10:25 AM, Mark Lawrence > wrote: >> I've been running 64 bit Python on Windows for years with no problems. Why >> use 32 bit? I certainly don't understand why you'd need to. > > It seems to be easier to find 32-bit binaries for libraries.

Re: Question

2016-03-07 Thread Mark Lawrence
On 07/03/2016 17:42, Ian Kelly wrote: On Mon, Mar 7, 2016 at 10:25 AM, Mark Lawrence wrote: On 07/03/2016 16:57, Ian Kelly wrote: On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: I am trying to download Python but I have windows 10 and I do not see a 64 bit download for my operating syst

Re: Question

2016-03-07 Thread mm0fmf
On 07/03/2016 18:09, Jon Ribbens wrote: On 2016-03-07, Ian Kelly wrote: On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: I am trying to download Python but I have windows 10 and I do not see a 64 bit download for my operating system. Do you have a 64 bit for windows? What page are you loo

Re: Question

2016-03-07 Thread Chris Warrick
On 7 March 2016 at 19:09, Jon Ribbens wrote: > On 2016-03-07, Ian Kelly wrote: >> On Mon, Mar 7, 2016 at 9:39 AM, Ben Morales wrote: >>> I am trying to download Python but I have windows 10 and I do not see a 64 >>> bit download for my operating system. Do you have a 64 bit for windows? >> >> Wh

Re: Question

2016-03-07 Thread Random832
On Mon, Mar 7, 2016, at 13:09, Jon Ribbens wrote: > It only appears to have downloads for 32-bit, or 64-bit AMD processors, > not 64-bit Intel processors. Current 64-bit processors produced by Intel use the "AMD64" architecture, not the Intel IA-64 (Itanium) architecture. -- https://mail.python.o

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 07/03/2016 15:31, Chris Angelico wrote: On Tue, Mar 8, 2016 at 12:25 AM, BartC wrote: (The Python version of that program is here: http://pastebin.com/cHx3UhQb. It should work with any Python.) Actually, it won't work with any Python - not if it gets a broken file. Your abortjpeg() funct

Re: Question

2016-03-07 Thread Jon Ribbens
On 2016-03-07, mm0fmf wrote: > On 07/03/2016 18:09, Jon Ribbens wrote: >> It only appears to have downloads for 32-bit, or 64-bit AMD processors, >> not 64-bit Intel processors. > > You didn't read the bit that says > > "The binaries for AMD64 will also work on processors that implement the > Int

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Mark Lawrence
On 07/03/2016 11:02, BartC wrote: PyPy I think is only compatible with Python 3 code (there are a few other issues too). Quoting from http://doc.pypy.org/en/latest/release-0.7.0.html "The interpreter and object model implementations shipped with the 0.7 version can run on their own and impl

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 17:38, Chris Angelico wrote: On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tell you what you need to import to make somet

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 5:34 AM, BartC wrote: > On 07/03/2016 15:31, Chris Angelico wrote: >> >> On Tue, Mar 8, 2016 at 12:25 AM, BartC wrote: > > >>> (The Python version of that program is here: >>> http://pastebin.com/cHx3UhQb. It should work with any Python.) >> >> >> Actually, it won't work wi

Re: Question

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 11:51 AM, Jon Ribbens wrote: > I must say that Python on Windows was a very poor experience indeed, > "virtualenv" does not work and "venv" refuses to create the 'activate' > shell script so does not work either I've used both of these on Windows (although not recently) and

Re: Question

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 5:51 AM, Jon Ribbens wrote: > I must say that Python on Windows was a very poor experience indeed, > "virtualenv" does not work and "venv" refuses to create the 'activate' > shell script so does not work either (and pygame doesn't work, but > that's presumably not Python's f

Re: Question

2016-03-07 Thread Andrew Farrell
I'm going to echo Chris Angelo's suggestion #2 to use a python distribution. This page has the links to download Anaconda. It is free and if you need to download libraries which require compiled external code like numpy you can just run `conda install numpy`. O

Re: importing

2016-03-07 Thread MRAB
On 2016-03-07 19:08, Mark Lawrence wrote: On 07/03/2016 17:38, Chris Angelico wrote: On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrote: The documentation should tel

fnmatch() vs. glob.glob()

2016-03-07 Thread Jinghui Niu
Hi, I've been studying python 3 modules. I'm a bit confused about the possibly overlap between fnmatch() and glob(), they seem to achieve the same goals exactly. Why duplicate? Or maybe something I've missed? Thank you. -- https://mail.python.org/mailman/listinfo/python-list

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 07/03/2016 19:10, Chris Angelico wrote: On Tue, Mar 8, 2016 at 5:34 AM, BartC wrote: def abortjpeg(mess): print ("Error:",mess) raise Here's my Python: RuntimeError: No active exception to reraise OK I'll have a look. (Or maybe just change 'raise' to 'exit(0)'. It just nee

Re: Question

2016-03-07 Thread justin walters
Unfortunately, it's difficult for the core devs to know every hardware and os combination there is. Maybe you could submit a bug report? On Mar 7, 2016 10:56 AM, "Jon Ribbens" wrote: > On 2016-03-07, mm0fmf wrote: > > On 07/03/2016 18:09, Jon Ribbens wrote: > >> It only appears to have downloads

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 7:19 AM, BartC wrote: >>> I disagree. The program does its job perfectly (you will have to take it >>> further to verify the results, such as writing out the .ppm file and >>> viewing >>> the contents). >>> >>> But Py3 is slower doing this task than Py2 by 10 or 20% (or even

Re: fnmatch() vs. glob.glob()

2016-03-07 Thread Ben Finney
Jinghui Niu writes: > Hi, I've been studying python 3 modules. I'm a bit confused about the > possibly overlap between fnmatch() and glob(), they seem to achieve > the same goals exactly. Why duplicate? From the module documentation: Note that unlike fnmatch.fnmatch(), glob treats filenames

Re: importing

2016-03-07 Thread Mark Lawrence
On 07/03/2016 20:07, MRAB wrote: On 2016-03-07 19:08, Mark Lawrence wrote: On 07/03/2016 17:38, Chris Angelico wrote: On Tue, Mar 8, 2016 at 4:23 AM, Tony van der Hoff wrote: Thanks to all who replied to my cry for help; I understand it better now. But: On 07/03/16 16:08, Chris Angelico wrot

Re: Struggeling with collections

2016-03-07 Thread Roel Schroeven
Faling Dutchman schreef op 2016-03-07 09:24: class Item: def __init__(self, id, productId, quantity, pageCount, files, option, metadata): self.id = id self.productId = productId self.quantity = quantity self.pageCount = pageCount self.files = files

Re: importing

2016-03-07 Thread Terry Reedy
On 3/7/2016 12:23 PM, Tony van der Hoff wrote: However, more generally, how am I supposed to know that a module is part of a package, and needs a "magic" stanza to get a module loaded? The doc for a package usually mentions the submodules it contains, as in https://docs.python.org/3/library/tk

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Terry Reedy
On 3/7/2016 6:54 AM, Andrew Jaffe wrote: Dumb question, and this probably isn't the place for it, but the three Pythons being tested are: 64-bit CPython on Li... latest in branch '2.7' 64-bit CPython on Li... latest in branch '3.5' 64-bit CPython on Li... latest > I understand that the

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 07/03/2016 20:47, Chris Angelico wrote: On Tue, Mar 8, 2016 at 7:19 AM, BartC wrote: What can be more perfect for comparing two implementations? rosuav@sikorsky:~$ python2 -m timeit -s 'from fp import Float' 'Float("1234.567")' 100 loops, best of 3: 1.84 usec per loop rosuav@sikorsk

Pythonic love

2016-03-07 Thread Fillmore
learning Python from Perl here. Want to do things as Pythonicly as possible. I am reading a TSV, but need to skip the first 5 lines. The following works, but wonder if there's a more pythonc way to do things. Thanks ctr = 0 with open(prfile,mode="rt",encoding='utf-8') as pfile: for line i

Re: Pythonic love

2016-03-07 Thread Rob Gaddi
Fillmore wrote: > > learning Python from Perl here. Want to do things as Pythonicly as possible. > > I am reading a TSV, but need to skip the first 5 lines. The following > works, but wonder if there's a more pythonc way to do things. Thanks > > ctr = 0 > with open(prfile,mode="rt",encoding='utf-

Re: Pythonic love

2016-03-07 Thread sohcahtoa82
On Monday, March 7, 2016 at 2:51:50 PM UTC-8, Fillmore wrote: > learning Python from Perl here. Want to do things as Pythonicly as possible. > > I am reading a TSV, but need to skip the first 5 lines. The following > works, but wonder if there's a more pythonc way to do things. Thanks > > ctr =

breaking out of outer loops

2016-03-07 Thread Fillmore
I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? For the record, here's a Perl script of mine I'm trying to port...there may be 'malformed' lines in a TSV file I'm parsing that are better discarded than fix

Re: Pythonic love

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 3:51 PM, Fillmore wrote: > > learning Python from Perl here. Want to do things as Pythonicly as possible. > > I am reading a TSV, but need to skip the first 5 lines. The following works, > but wonder if there's a more pythonc way to do things. Thanks I'd probably use iterto

Re: Pythonic love

2016-03-07 Thread Fillmore
On 3/7/2016 6:03 PM, sohcahto...@gmail.com wrote: On a side note, your "with open..." line uses inconsistent quoting. > You have "" on one string, but '' on another. Thanks. I'll make sure I flog myself three times later tonight... -- https://mail.python.org/mailman/listinfo/python-list

Re: breaking out of outer loops

2016-03-07 Thread Ian Kelly
On Mon, Mar 7, 2016 at 4:09 PM, Fillmore wrote: > > I must be missing something simple because I can't find a way to break out > of a nested loop in Python. > > Is there a way to label loops? No, you can't break out of nested loops, apart from structuring your code such that return does what you

Re: Pythonic love

2016-03-07 Thread Mark Lawrence
On 07/03/2016 22:51, Fillmore wrote: learning Python from Perl here. Want to do things as Pythonicly as possible. I am reading a TSV, but need to skip the first 5 lines. The following works, but wonder if there's a more pythonc way to do things. Thanks ctr = 0 with open(prfile,mode="rt",encodi

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:17 PM, Ian Kelly wrote: On Mon, Mar 7, 2016 at 4:09 PM, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? No, you can't break out of nested loops, wow...this is a bit of a WTF

Re: breaking out of outer loops

2016-03-07 Thread Rob Gaddi
Fillmore wrote: > > I must be missing something simple because I can't find a way to break > out of a nested loop in Python. > > Is there a way to label loops? > > For the record, here's a Perl script of mine I'm trying to port...there > may be 'malformed' lines in a TSV file I'm parsing that ar

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 9:39 AM, BartC wrote: > > What are you suggesting here? That all these Pythons are going to be faster > or slower than each other? I would guess that most of them are going to be > roughly the same, other than PyPy. If there was a fast version, then I would > have heard abou

Re: breaking out of outer loops

2016-03-07 Thread Chris Kaynor
On Mon, Mar 7, 2016 at 3:21 PM, Fillmore wrote: > On 3/7/2016 6:17 PM, Ian Kelly wrote: > >> On Mon, Mar 7, 2016 at 4:09 PM, Fillmore >> wrote: >> >>> >>> I must be missing something simple because I can't find a way to break >>> out >>> of a nested loop in Python. >>> >>> Is there a way to labe

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:29 PM, Rob Gaddi wrote: You're used to Perl, you're used to exceptions being A Thing. This is Python, and exceptions are just another means of flow control. class MalformedLineError(Exception): pass for line in file: try: for part in line.split('\t'):

Re: breaking out of outer loops

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 10:09 AM, Fillmore wrote: > For the record, here's a Perl script of mine I'm trying to port...there may > be 'malformed' lines in a TSV file I'm parsing that are better discarded > than fixed. > > my $ctr = 0; > OUTER: > while($line = ) { > > $ctr++; > if ($ctr < 5)

Re: breaking out of outer loops

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 10:42 AM, Chris Kaynor wrote: > And the same rough example, using an exception without a function: > > for file in files: > try: > for line in file: > section = line.split() > for section in line: > if sectionCorrupt: >

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 6:09 PM, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Thanks to everyone who has tried to help so far. I suspect this may be a case where I just need to get my head around a new paradigm -- https://mail.

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Ben Finney
BartC writes: > On 07/03/2016 20:47, Chris Angelico wrote: > > Look! Creating a floating-point value is faster under Python 2 than > > Python 3. What could be more perfect? > > > This is like a microbenchmark in that it doesn't tell you anything > > about real-world usage. > > Microbenchmarks hav

Re: breaking out of outer loops

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 11:02 AM, Fillmore wrote: > On 3/7/2016 6:09 PM, Fillmore wrote: >> >> >> I must be missing something simple because I can't find a way to break >> out of a nested loop in Python. > > > Thanks to everyone who has tried to help so far. I suspect this may be a > case where I j

What will I get when reading from a file? (was: Pyhon 2.x or 3.x, which is faster?)

2016-03-07 Thread Ben Finney
BartC writes: > I'm using [a third-party library function] because this kind of file > reading in Python is a mess. If I do a read, will I get a string, a > byte sequence object, a byte-array, or array-array, or what? That's a strange statement; there is virtually no mystery in what you'll get f

Re: breaking out of outer loops

2016-03-07 Thread Fillmore
On 3/7/2016 7:08 PM, Chris Angelico wrote: Yep, which is why we're offering a variety of new paradigms. Because it's ever so much easier to get your head around three than one! We are SO helpful, guys. So helpful. :) not too dissimilarly from human languages, speaking a foreign language is

Re: breaking out of outer loops

2016-03-07 Thread Joel Goldstick
On Mon, Mar 7, 2016 at 7:13 PM, Fillmore wrote: > On 3/7/2016 7:08 PM, Chris Angelico wrote: > > >> Yep, which is why we're offering a variety of new paradigms. Because >> it's ever so much easier to get your head around three than one! >> >> We are SO helpful, guys. So helpful. :) >> > > not too

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 07/03/2016 23:40, Chris Angelico wrote: On Tue, Mar 8, 2016 at 9:39 AM, BartC wrote: I'm using it because this kind of file reading in Python is a mess. If I do a read, will I get a string, a byte sequence object, a byte-array, or array-array, or what? Uhh you'll get either a text st

Re: breaking out of outer loops

2016-03-07 Thread Mark Lawrence
On 07/03/2016 23:09, Fillmore wrote: I must be missing something simple because I can't find a way to break out of a nested loop in Python. Is there a way to label loops? For the record, here's a Perl script of mine I'm trying to port...there may be 'malformed' lines in a TSV file I'm parsing

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Mark Lawrence
On 08/03/2016 00:22, BartC wrote: The slow speed of Python (and a number of other scripting languages) is well known. But obviously that is not any sort of issue, and these people working flat out on tracing JIT compilers are all wasting their time too! The slow speed of Python hasn't stoppe

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Chris Angelico
On Tue, Mar 8, 2016 at 11:22 AM, BartC wrote: > > (Is a byte string the same as a byte array? Is a byte array the same as an > array.array? If I remove this line from my code, where 'data' has just been > read from a file: > >data=array.array('B',data) > > then it still works - Python 3. But n

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread MRAB
On 2016-03-08 00:22, BartC wrote: On 07/03/2016 23:40, Chris Angelico wrote: On Tue, Mar 8, 2016 at 9:39 AM, BartC wrote: I'm using it because this kind of file reading in Python is a mess. If I do a read, will I get a string, a byte sequence object, a byte-array, or array-array, or what?

Re: fnmatch() vs. glob.glob()

2016-03-07 Thread Jinghui Niu
On Monday, March 7, 2016 at 1:37:45 PM UTC-8, Ben Finney wrote: > Jinghui Niu writes: > > > Hi, I've been studying python 3 modules. I'm a bit confused about the > > possibly overlap between fnmatch() and glob(), they seem to achieve > > the same goals exactly. Why duplicate? > > >From the modul

Re: fnmatch() vs. glob.glob()

2016-03-07 Thread Ben Finney
Jinghui Niu writes: > Thank you for your reply. So if for a beginner learner who doesn't > care so much about Unix-compliant, which one is a better choice for > learning purpose? Learn to care about the difference :-) They are both useful and both do different things. -- \ “I must say tha

Re: fnmatch() vs. glob.glob()

2016-03-07 Thread Jinghui Niu
On Monday, March 7, 2016 at 5:00:57 PM UTC-8, Ben Finney wrote: > Jinghui Niu writes: > > > Thank you for your reply. So if for a beginner learner who doesn't > > care so much about Unix-compliant, which one is a better choice for > > learning purpose? > > Learn to care about the difference :-)

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread BartC
On 08/03/2016 00:05, Ben Finney wrote: BartC writes: On 07/03/2016 20:47, Chris Angelico wrote: Look! Creating a floating-point value is faster under Python 2 than Python 3. What could be more perfect? This is like a microbenchmark in that it doesn't tell you anything about real-world usag

Re: Pyhon 2.x or 3.x, which is faster?

2016-03-07 Thread Mark Lawrence
On 08/03/2016 01:00, BartC wrote: If your efforts manage to double the speed of reading file A, then probably the reading file B is also going to be improved! In practice you use a variety of files, but one at a time will do. What is the difference in your timing when you first read the file,

  1   2   >