Re: Python-list Digest, Vol 99, Issue 27
I do not want GUI, I just want a console application which will read a single character input. When you read from stdin for example, you have it to be terminated. 2011/12/6 : > Send Python-list mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: Questions about LISP and Python. (Xah Lee) > 2. Re: Questions about LISP and Python. (Chris Angelico) > 3. Re: 70% [* SPAM *] Re: Re: multiprocessing.Queue blocks when > sending large object (Dennis Lee Bieber) > 4. Single key press (Sergi Pasoev) > 5. Re: Fwd: class print method... (Suresh Sharma) > 6. Re: Single key press (8 Dihedral) > 7. Re: Single key press (8 Dihedral) > 8. Re: Scope of variable inside list comprehensions? (Rainer Grimm) > 9. Re: Questions about LISP and Python. (alex23) > 10. Re: Questions about LISP and Python. (Matt Joiner) > > > -- Message transféré -- > From: Xah Lee > To: [email protected] > Date: Mon, 5 Dec 2011 20:36:45 -0800 (PST) > Subject: Re: Questions about LISP and Python. > On Dec 5, 4:31 am, Tim Bradshaw wrote: >> On 2011-12-05 11:51:11 +, Xah Lee said: >> >> > python has more readible syntax, more modern computer language >> > concepts, and more robust libraries. These qualities in turn made it >> > popular. >> >> Yet you still post here: why? > > i don't like python, and i prefer emacs lisp. The primary reason is > that python is not functional, especially with python 3. The python > community is full of fanatics with their drivels. In that respect, > it's not unlike Common Lisp community and Scheme lisp community. > > see also: > > 〈Python Documentation Problems〉 > http://xahlee.org/perl-python/python_doc_index.html > > 〈Computer Language Design: What's List Comprehension and Why is It > Harmful?〉 > http://xahlee.org/comp/list_comprehension.html > > 〈Lambda in Python 3000〉 > http://xahlee.org/perl-python/python_3000.html > > 〈What Languages to Hate〉 > http://xahlee.org/UnixResource_dir/writ/language_to_hate.html > > 〈Xah on Programing Languages〉 > http://xahlee.org/Periodic_dosage_dir/comp_lang.html > > Xah > > > > -- Message transféré -- > From: Chris Angelico > To: [email protected] > Date: Tue, 6 Dec 2011 16:10:27 +1100 > Subject: Re: Questions about LISP and Python. > On Tue, Dec 6, 2011 at 3:36 PM, Xah Lee wrote: >> i don't like python, and i prefer emacs lisp. The primary reason is >> that python is not functional, especially with python 3. The python >> community is full of fanatics with their drivels. In that respect, >> it's not unlike Common Lisp community and Scheme lisp community. > > So you hate Python. Fine. Why post here? Why not just abandon Python > as a dead loss and go code in Lithp? > > Clearly something is keeping you here. Is it that there's something > about Python that you really like, or are you just trolling? > > ChrisA > > > > -- Message transféré -- > From: Dennis Lee Bieber > To: [email protected] > Date: Mon, 05 Dec 2011 21:15:09 -0800 > Subject: Re: 70% [* SPAM *] Re: Re: multiprocessing.Queue blocks when sending > large object > On Mon, 5 Dec 2011 18:49:44 +0100, DPalao > wrote: > >>Obviously it was not me who added the disgusting "70% [* SPAM *]" string to >>the subject. And I'd like to know the answer too. >> > Based upon your headers, somewhere your message went through a spam > check program... > > X-Greylist: Sender succeeded SMTP AUTH, not delayed by > milter-greylist-4.3.7 > (monster.roma2.infn.it [141.108.255.100]); > Mon, 05 Dec 2011 09:02:22 +0100 (CET) > X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, > Antispam-Data: 2011.12.5.74814 > X-PMX-Spam: 70% > X-PMX-Spam-report: The following antispam rules were triggered by this > message: > Rule Score Description > RDNS_SUSP_FORGED_FROM 3.500 From domain appears to be forged, > and arrived via a host with a known suspicious rDNS. > SXL_IP_DYNAMIC 3.000 Received via a known dynamic IP (SXL lookup): > 34.140.47.93.fur > FORGED_FROM_GMAIL 0.100 Appears to forge gmail in the from > FROM_NAME_ONE_WORD 0.050 Name in From header is a single word > BODYTEXTP_SIZE_3000_LESS 0.000 Body size of the text/plain part is > less > than 3k > BODY_SIZE_1500_1599 0.000 Message body size is 1500 to 1599 bytes > BODY_SIZE_2000_LESS 0.000 Message body size is less than 2000 bytes. > BODY_SIZE_5000_LESS 0.000 Message body siz
Re: Single key press
On Dec 6, 3:49 pm, Sergi Pasoev wrote: > I wonder if it is realistic to get a single key press in Python > without ncurses or any similar library. It's possible using Tkinter in the standard library: http://www.daniweb.com/software-development/python/code/216830 -- http://mail.python.org/mailman/listinfo/python-list
Re: Single key press
On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: > Hi. > > I wonder if it is realistic to get a single key press in Python without > ncurses or > any similar library. In single key press I mean something like j and k > in Gnu less > program, you press the key and and it is captured by the script without > need to press enter afterwards Coincidentally, I was working on that exact function last night, so you inspired me to put it up on the Python cookbook. This version should work on any POSIX system such as Linux, as well as Windows. I don't know if it will work on Macintosh. http://code.activestate.com/recipes/577977-get-single-keypress/ -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: struct calcsize discrepency?
On Mon, 05 Dec 2011 00:20:32 -0800, Mark Dickinson wrote:
>> May be, yes, but since calcsize() is returning 12 when the elements
>> are put in the other order, it would seem to be not counting such
>> padding.
>
> Indeed. That's arguably a bug in the struct module,
There's no "arguably" about it. The documentation says:
Native size and alignment are determined using the C compiler’s sizeof
expression.
But given:
struct { unsigned long long a; char b[4]; } foo;
struct { char b[4]; unsigned long long a; } bar;
sizeof(foo) will always equal sizeof(bar). If long long is 8 bytes and has
8-byte alignment, both will be 16.
If you want consistency with the in-memory representation used by
C/C++ programs (and the on-disk representation used by C/C++ programs
which write the in-memory representation directly to file), use ctypes;
e.g.:
>>> from ctypes import *
>>> class foo(Structure):
_fields_ = [
("a", c_ulonglong),
("b", c_char * 4)]
>>> sizeof(foo)
16
--
http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
i don't like python, and i prefer emacs lisp. The primary reason is that python is not functional, especially with python 3. The python community is full of fanatics with their drivels. In that respect, it's not unlike Common Lisp community and Scheme lisp community. What functional programming features do you use, Xah? Last time I've checked, you didn't care about closures. In this respect, Python is better at functional programming than Emacs Lisp. Do you just like writing arbitrarily long expression? Or you think that eval is functional? -- http://mail.python.org/mailman/listinfo/python-list
Re: Backspace does not erase in stdout
On Mon, 05 Dec 2011 16:23:55 +, Grant Edwards wrote: >> Emitting "\b \b" is one very common way to do a destructive backspace. >> Inelegant? Perhaps, but a common inelegance. > > That's pretty much the only way I've seen it done for the past 25 > years. ... before which, it was BS-DEL-BS. DEL being 127 means that it punches through all of the holes on the paper tape, causing whatever was there previously to be replaced with a DEL character. BS-SPC-BS would only punch through one of the holes. -- http://mail.python.org/mailman/listinfo/python-list
Re: Single key press
On 6/12/11 09:48:39, Steven D'Aprano wrote: On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: Hi. I wonder if it is realistic to get a single key press in Python without ncurses or any similar library. In single key press I mean something like j and k in Gnu less program, you press the key and and it is captured by the script without need to press enter afterwards Coincidentally, I was working on that exact function last night, so you inspired me to put it up on the Python cookbook. This version should work on any POSIX system such as Linux, as well as Windows. I don't know if it will work on Macintosh. http://code.activestate.com/recipes/577977-get-single-keypress/ It works fine on MacOS/X, but probably not on MacOS Classic. -- HansM -- http://mail.python.org/mailman/listinfo/python-list
Re: Single key press
On Tue, 06 Dec 2011 10:19:55 +0430, Sergi Pasoev wrote: > I wonder if it is realistic to get a single key press in Python > without ncurses or any similar library. On Unix, you need to use termios.tcsetattr() to disable "canonical mode". Otherwise, the tty driver will only pass data up to the application when the user enters a newline or EOF. If you do this, you also need to handle SIGTSTP and SIGCONT, restoring the original terminal settings on SIGTSTP (typically generated by Ctrl-Z) and restoring the application's setting on SIGCONT. -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope of variable inside list comprehensions?
On Tuesday, December 6, 2011 2:42:35 PM UTC+8, Rainer Grimm wrote: > Hello, > > > try: > > songs = [Song(id) for id in song_ids] > > except Song.DoesNotExist: > > print "unknown song id (%d)" % id > that's is a bad programming style. So it will be forbidden with python 3. The > reason is that list comprehension is a construct from the functional world. > It's only syntactic sugar for the functions map and filter. So functions have > to be pure functions. To say it in other words, they have to be side-effect > free. But the python construct from above pollutes the namespace with name id. > > Greetings from Rottenburg, > Rainer The list might have to grow in a careless way that might lead to a crash in the for inside a list that can't be trapped for errors directly. -- http://mail.python.org/mailman/listinfo/python-list
Re: Scope of variable inside list comprehensions?
Steven D'Aprano wrote: On Mon, 05 Dec 2011 19:57:15 +0100, Jean-Michel Pichavant wrote: The proper way to propagate information with exceptions is using the exception itself: try: songs = [Song(_id) for _id in song_ids] except Song.DoesNotExist, exc: print exc I'm not entirely sure that this is the proper way to propagate the exception. I see far to many people catching exceptions to print them, or worse, to print a generic, useless message like "an error occurred". [snip] You misread me, I was referering to passing *information* with exception (in other words, use the exception attributes). In the example I gave, the exception has the songId value responsible for raising the error. I totaly second your opinion on how poor the above handler is (hmm not sure about this grammar construct, it sounds like a Yoda sentence). JM -- http://mail.python.org/mailman/listinfo/python-list
the deceptive continuous assignments
Hi, I just figured out this with Python3.2 IDLE: >>> class k: pass >>> x=k() >>> x.thing = 1 >>> x.thing 1 >>> x = x.thing = 1 Traceback (most recent call last): File "", line 1, in x = x.thing = 1 AttributeError: 'int' object has no attribute 'thing' >>> x 1 >>> when I do x=x.thing=1, I thought it would be like in C, 1 is first assigned to x.thing, then it is further assigned to x. But what seems to be going on here is that 1 is first assigned to x, then to x.thing (which causes an error). Any reason why would Python deviate from C in this regard? Thanks! Yingjie -- http://mail.python.org/mailman/listinfo/python-list
whitespace cleanup
Now on Emacs I have a hook before every save that cleans up all the "wrong" white spaces, with the 'whitespace-cleanup' function. I would like that also for my non emacsers colleagues, and possibly with a Python script. I looked up around but I can't find anything useful, any advice? Thanks, Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: whitespace cleanup
On 06/12/2011 09:28, Andrea Crotti wrote: > Now on Emacs I have a hook before every save that cleans up all the > "wrong" white spaces, > with the 'whitespace-cleanup' function. > > I would like that also for my non emacsers colleagues, and possibly with > a Python script. > I looked up around but I can't find anything useful, any advice? You can use the strip() method: [http://docs.python.org/release/2.3/lib/module-string.html] While reading the file as strings, the strip() method rips out all of the extra whitespace. > Thanks, > Andrea > Good luck! -- Att; Pedro Henrique G. Souto -- http://mail.python.org/mailman/listinfo/python-list
Re: whitespace cleanup
On 12/06/2011 11:49 AM, Pedro Henrique G. Souto wrote: On 06/12/2011 09:28, Andrea Crotti wrote: > Now on Emacs I have a hook before every save that cleans up all the > "wrong" white spaces, > with the 'whitespace-cleanup' function. > > I would like that also for my non emacsers colleagues, and possibly with > a Python script. > I looked up around but I can't find anything useful, any advice? You can use the strip() method: [http://docs.python.org/release/2.3/lib/module-string.html] While reading the file as strings, the strip() method rips out all of the extra whitespace. > Thanks, > Andrea > Good luck! Well it's not so simple, I clearly don't want to strip out whitespace in the beginning of the line, or my nice code will break miserably ;) So I think some magic using tokens/regexp/python grammar would be useful to do something reliable, or is it easier than that? -- http://mail.python.org/mailman/listinfo/python-list
Re: whitespace cleanup
On Tue, Dec 6, 2011 at 10:59 PM, Andrea Crotti wrote: > Well it's not so simple, I clearly don't want to strip out whitespace in the > beginning of the line, > or my nice code will break miserably ;) The question is: What is "wrong" whitespace? Whatever you declare to be wrong, you can probably come up with a regexp or other spec that will catch it (or conversely, declare some pattern to be "right" and look for anything else). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: whitespace cleanup
On 06/12/2011 10:06, Chris Angelico wrote: On Tue, Dec 6, 2011 at 10:59 PM, Andrea Crotti wrote: Well it's not so simple, I clearly don't want to strip out whitespace in the beginning of the line, or my nice code will break miserably ;) The question is: What is "wrong" whitespace? Whatever you declare to be wrong, you can probably come up with a regexp or other spec that will catch it (or conversely, declare some pattern to be "right" and look for anything else). ChrisA Something like PythonTidy does what you want? http://pypi.python.org/pypi/PythonTidy If you like to write your own script, or if what you want is similar, but not the same, the source code is a good place to start: http://lacusveris.com/PythonTidy/PythonTidy-1.20.python -- Att; Pedro Henrique G. Souto -- http://mail.python.org/mailman/listinfo/python-list
Re: the deceptive continuous assignments
On 12/6/2011 6:06 AM, Yingjie Lan wrote: Hi, I just figured out this with Python3.2 IDLE: class k: pass x=k() x.thing = 1 x.thing 1 x = x.thing = 1 Traceback (most recent call last): File "", line 1, in x = x.thing = 1 AttributeError: 'int' object has no attribute 'thing' x 1 when I do x=x.thing=1, I thought it would be like in C, 1 is first assigned to x.thing, then it is further assigned to x. In C, assignments are expressions, not statements. a = b = c is parsed as a = (b = c). a get the result of (b = c), which happens to be c. In Python, the syntax really should be a =, b = c in that the assignments are more in parallel. But what seems to be going on here is that 1 is first assigned to x, then to x.thing (which causes an error). Any reason why would Python deviate from C in this regard? Python is consistently left to right in expression evaluation. For assignment, it first does left to right on the source side, and then on the target side. "An assignment statement evaluates the expression list (remember that this can be a single expression or a comma-separated list, the latter yielding a tuple) and assigns the single resulting object to each of the target lists, from left to right." You have two target lists. x,x.thing = 1,2 would assign 1 to x and then get an error trying to assign a different object to x.thing. In your case, you get an error trying to assign the same object rather than a different object, but the principle is the same. "WARNING: Although the definition of assignment implies that overlaps between the left-hand side and the right-hand side are ‘safe’ (for example a, b = b, a swaps two variables), overlaps within the collection of assigned-to variables are not safe!" You found an unsafe overlap. x.thing = x = 1 would work, though it seems strange (and unlikely in practice) to rebind x to an int after it is bound to a class k instance. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: the deceptive continuous assignments
On Tue, Dec 6, 2011 at 11:20 PM, Terry Reedy wrote:
> You found an unsafe overlap.
> x.thing = x = 1
> would work, though it seems strange (and unlikely in practice) to rebind x
> to an int after it is bound to a class k instance.
This code is starting to look like it wants to work with a linked list.
>>> class node:
def __init__(self,x):
self.payload=x
self.next=None
def walk(self):
print("My payload is: "+self.payload)
if self.next: self.next.walk()
>>> head=tail=node("This")
>>> tail.next=tail=node("is")
>>> tail.next=tail=node("a")
>>> tail.next=tail=node("test.")
>>> head.walk()
My payload is: This
My payload is: is
My payload is: a
My payload is: test.
>>>
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Re: whitespace cleanup
On 12/06/2011 12:17 PM, Pedro Henrique G. Souto wrote: Something like PythonTidy does what you want? http://pypi.python.org/pypi/PythonTidy If you like to write your own script, or if what you want is similar, but not the same, the source code is a good place to start: http://lacusveris.com/PythonTidy/PythonTidy-1.20.python For wrong space I meant what is not pep8 complaint.. Actually even pep8.py is quite good in finding out these things, but it just warns about and doesn't propose to fix the problems. PythonTidy is more what I need, using easy_install doesn't work though, but the direct link on the pypi page does.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
On Dec 5, 11:10 pm, Chris Angelico wrote: > On Tue, Dec 6, 2011 at 3:36 PM, Xah Lee wrote: > > i don't like python, and i prefer emacs lisp. The primary reason is > > that python is not functional, especially with python 3. The python > > community is full of fanatics with their drivels. In that respect, > > it's not unlike Common Lisp community and Scheme lisp community. > > So you hate Python. Fine. Why post here? Why not just abandon Python > as a dead loss and go code in Lithp? > > Clearly something is keeping you here. Is it that there's something > about Python that you really like, or are you just trolling? I would say Mr. Lee does in fact find some usefulness of Python (as do i) HOWEVER he also laments the asinities that plague the language, the documentation, and especially, this community. Anyone who would take the time to write *articulate* suggestions for grave deficiencies in the Python documentation must care. Mr. Lee, has documented many of the atrocities of the doc in his fine website. I just recently finished reading a few more of his fine suggestions and I especially enjoyed the "os.path.split" rant. PRICELESS! Listen, python is a great language, but not a perfect one. You people seem to get all upset at even the slightest suggestion that Python is not perfect. The haughty arrogance i see day after day around me just makes me sick. Grow up! You are not perfect and neither is Python... or Guido for that matter. This community is chalk full (from top to bottom!) of arrogant, tech geeking, unix hacks who look down on the "outsiders" as excrement. I believe it's high time for these folks to eat a big slice of humble pie -- i just fear there is not enough to go around! O_O -- http://mail.python.org/mailman/listinfo/python-list
Re: whitespace cleanup
So apparently PythonTidy uses the AST (the compiler module) to find out the problems, and generates new nodes with a put method to write out the code with the fix. An awful lot of code is needed to make it work apparently, not very neat. Pep8 instead uses tokenize and regular expressions only, and the code is much neater, not sure how is possible to make it fix things though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
On Wed, Dec 7, 2011 at 12:13 AM, Rick Johnson wrote: > This community is chalk full (from top to bottom!) of arrogant, tech > geeking, unix hacks who look down on the "outsiders" as excrement. I > believe it's high time for these folks to eat a big slice of humble > pie -- i just fear there is not enough to go around! O_O It's also chock full (note that) of trolls. Do we need a [email protected]? You two could discuss the upcoming Pyson 4000 (that's Python with a Lithp) and how it's going to revolutionize the world. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some IPC pointers
I'm surprised no one has mentioned zeromq as transport yet. It provides scaling from in proc (between threads) to inter-process and remote machines in a fairly transparent way. It's obviously not the python stdlib and as any system there are downsides too. Regards, Floris -- http://mail.python.org/mailman/listinfo/python-list
Re: Backspace does not erase in stdout
On Dec 6, 3:27 am, Nobody wrote: > On Mon, 05 Dec 2011 16:23:55 +, Grant Edwards wrote: > >> Emitting "\b \b" is one very common way to do a destructive backspace. > >> Inelegant? Perhaps, but a common inelegance. > > > That's pretty much the only way I've seen it done for the past 25 > > years. > > ... before which, it was BS-DEL-BS. > > DEL being 127 means that it punches through all of the holes on the paper > tape, causing whatever was there previously to be replaced with a DEL > character. BS-SPC-BS would only punch through one of the holes. *Wise Observer Speculates:* Why on earth are we "21st century slaves" to an archaic mid 20th century technology that punches holes in paper tape? Anyone? >>> isinstance(Progress, None) True -- http://mail.python.org/mailman/listinfo/python-list
Re: Backspace does not erase in stdout
On Wed, Dec 7, 2011 at 12:21 AM, Rick Johnson wrote: > *Wise Observer Speculates:* Why on earth are we "21st century slaves" > to an archaic mid 20th century technology that punches holes in paper > tape? Anyone? > isinstance(Progress, None) > True I'm not sure. Let's see... * Manned, powered, heavier-than-air flight: A hundred years. * TCP/IP: Thirty years. * Sliced bread: Eighty years. (What was the greatest thing BEFORE sliced bread?) * The English language: A few hundred, depending on how you count Why are we still eating sliced bread on board aeroplanes while posting in English on internet forums? Clearly we've made no progress since then. What language and communication protocol do you propose for the new python-troll-list? Getting back to the point though... The use of 127 for DEL is a consequence of the exact technology of paper tape. However, the question of whether BS is destructive or not is separate. Should it parallel other characters (draw character at cursor then advance cursor, vs retard cursor then erase character at cursor), or should it parallel cursor movement (eg carriage return, line feed, vertical tab)? If your BS is defined nondestructively, you can implement the destructive version with three characters; if it's defined destructively, you can't implement a nondestructive without some fiddliness (some systems use characters 28-31 for cursor movement). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Need some IPC pointers
What about named pipes? I don't mind a bit of "if Windows do this, else, do that" as long I'm not coding two or more completely different approaches. I'm not too familiar with named pipes, though; perhaps someone with some experience could chime in. Apparently this didn't go through to Google Groups the first time; it may show up twice for some. -- CPython 3.2.2 | Windows NT 6.1.7601.17640 | Thunderbird 7.0 -- http://mail.python.org/mailman/listinfo/python-list
How to build 64-bit Python on Solaris with GCC?
I'd like to build a 64-bit version of Python on Solaris using gcc. I did a bit of Googling, but everything I came up with seemed old, inconclusive or assumes the use of the Sun Studio compiler, with which i have no experience. Does anyone have a recipe for the subject build? Thanks, -- Skip Montanaro - [email protected] - http://www.smontanaro.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Backspace does not erase in stdout
In article , Nobody wrote: > On Mon, 05 Dec 2011 16:23:55 +, Grant Edwards wrote: > > >> Emitting "\b \b" is one very common way to do a destructive backspace. > >> Inelegant? Perhaps, but a common inelegance. > > > > That's pretty much the only way I've seen it done for the past 25 > > years. > > ... before which, it was BS-DEL-BS. > > DEL being 127 means that it punches through all of the holes on the paper > tape, causing whatever was there previously to be replaced with a DEL > character. BS-SPC-BS would only punch through one of the holes. I don't remember having a DEL key on the ASR-33. It did have a RUBOUT key (http://regmedia.co.uk/2010/06/21/teletype_hereis.jpg) which performed the function you describe. I don't remember if that actually sent a 177 code over the wire or if it was a purely local function. Also, the BS code only caused the printhead to back up. If you wanted to back up the tape, you had to press the "B. SP." button the the punch (http://pichotjm.free.fr/Multi8/TTY/ASR33-3.html). Of course, sending a BS-SPS-BS sequence on a printing terminal didn't do anything about erasing what had previously been printed. To do that, you needed one of those fancy vee-de-oh things. On the ASR-33, to prevent passwords from being readable, you either disabled echo, or sent something like BS-*-BS-X-BS-$-BS-%-BS-#-BS-@-BS-&-BS-H-BS-Z-BS-M in the hopes that nothing would be readable under all that garbage. -- http://mail.python.org/mailman/listinfo/python-list
Re: Backspace does not erase in stdout
In article , Rick Johnson wrote: > *Wise Observer Speculates:* Why on earth are we "21st century slaves" > to an archaic mid 20th century technology that punches holes in paper > tape? Anyone? Or to an archaic mid 20th century technology that limited lines to 80 characters? -- http://mail.python.org/mailman/listinfo/python-list
Re: Single key press
On 2011-12-06, Sergi Pasoev wrote: > I wonder if it is realistic to get a single key press in Python > without ncurses or > any similar library. Yes. Just put the tty associated with stdin in raw mode and make single byte read() calls on it. Remember to restore the tty settings when your program exits. -- Grant Edwards grant.b.edwardsYow! World War III? at No thanks! gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Backspace does not erase in stdout
On 2011-12-06, Nobody wrote: > On Mon, 05 Dec 2011 16:23:55 +, Grant Edwards wrote: > >>> Emitting "\b \b" is one very common way to do a destructive backspace. >>> Inelegant? Perhaps, but a common inelegance. >> >> That's pretty much the only way I've seen it done for the past 25 >> years. > > ... before which, it was BS-DEL-BS. > > DEL being 127 means that it punches through all of the holes on the > paper tape, causing whatever was there previously to be replaced with > a DEL character. > BS-SPC-BS would only punch through one of the holes. Ah yes. And when you read a tape, you silently ignored DEL characters. I had completely fogotten about that. I only used paper tape very briefly, and only for storage, never as a "live" medium for editing. -- Grant Edwards grant.b.edwardsYow! I own seven-eighths of at all the artists in downtown gmail.comBurbank! -- http://mail.python.org/mailman/listinfo/python-list
Re: Single key press
On Tuesday, December 6, 2011 11:22:18 PM UTC+8, Grant Edwards wrote: > On 2011-12-06, Sergi Pasoev wrote: > > > I wonder if it is realistic to get a single key press in Python > > without ncurses or > > any similar library. > > Yes. Just put the tty associated with stdin in raw mode and make > single byte read() calls on it. Remember to restore the tty settings > when your program exits. > > -- > Grant Edwards grant.b.edwardsYow! World War III? > at No thanks! > gmail.com Cheers to virus scan software that has to scan fast and easily for all files under a drive. Easy clean up in APPS. -- http://mail.python.org/mailman/listinfo/python-list
Referring to the class name from a class variable where inheritance is involved
I want to set up an inheritance hierarchy. The base class will define a string value which should include the class name, but I don't want people who inherit from my class to have to remember to override the value. If I do this using an instance variable, it's reasonably easy: >>> class Base: ... def __init__(self): ... self.key = 'Key_for_' + self.__class__.__name__ ... def display(self): ... print self.key ... >>> class Inherited(Base): ... pass ... >>> b = Base() >>> i = Inherited() >>> b.display() Key_for_Base >>> i.display() Key_for_Inherited Rather than having the key for every instance, I'd like to use a class variable, but I can't see how I'd make that work (a class variable which is inherited but has a different value in derived classes). I could use a classmethod,but that feels like even more overkill than an instance attribute. Is there a way of doing this via class variables or something, or more relevantly, I guess, what would be the idiomatic way of doing something like this? Thanks, Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Questions about LISP and Python.
On Tue, Dec 6, 2011 at 6:13 AM, Rick Johnson wrote: > I would say Mr. Lee does in fact find some usefulness of Python (as do > i) HOWEVER he also laments the asinities that plague the language, the > documentation, and especially, this community. > > Anyone who would take the time to write *articulate* suggestions for > grave deficiencies in the Python documentation must care. Mr. Lee, has > documented many of the atrocities of the doc in his fine website. I > just recently finished reading a few more of his fine suggestions and > I especially enjoyed the "os.path.split" rant. PRICELESS! I would be much more impressed if instead of simply whining about the documentation, Xah Lee would come off his high horse and actually submit a patch to fix it. That would be the mark of somebody who actually cares about the quality of the documentation. He seems to be suggesting that the problems he points out are just examples of systemic problems that make the whole incomprehensible, yet most of what he specifically identifies seems to be just copy editing for conciseness. What I find hilarious, though, is that Xah Lee has written his own Python documentation, and it's equally bad, if not worse. Just for example, I'll critique an arbitrary section. Let's talk about for loops. http://xahlee.org/perl-python/for_statement.html """This is a example of “for” statement.. a = range(1,51) # creates a list for x in a: if x % 2 == 0: print x, 'even' """ What is a "for" statement? What does it do? If I'm new to programming, I have no idea, and the above hasn't even attempted to introduce the concept, so that example is meaningless to me. Fortunately, he starts to explain it. """In the above, the percent “%” symbol calculates the remainder of division. The range(m,n) function gives a list from m to n-1""" Wait, I thought this section was about "for" statements. Why is the author suddenly (and poorly) explaining modulo division and the range function? These things belong in their own section. """Note that in this example, “for” goes over a list.""" Oh, okay, the author finally is telling us what "for" does. It is used to "go over" lists, apparently so that we can get to the other side. Note that this documentation still has not said anything at all about "looping" or "repeating" or "iterating" that might help me understand what that means. Instead we have "goes over". If I did not already understand what a "for" statement does, this would not make it any clearer. It reminds me of when I was 6 or so and I asked my mother what division was, and she told me that it's how many times a number "goes into" another number. Even though I was mathematically inclined, I didn't understand that all, because I had no idea what it meant for one number to enter another. """Each time making “x” the value of the element.""" Okay, apparently there's an element involved, and "x" is going to be its value. I really don't think I need to say anything more about this "sentence". """Python also supports “break” and “continue” to exit the loop. “break” will exit the loop. “continue” will skip code and start the next iteration.""" Finally the author breaks down and uses the words "loop" and "iteration", so if the reader actually makes it this far, then they might actually start to piece together everything that came before this. I also want to highlight his introduction of list comprehensions: http://xahlee.org/perl-python/list_comprehension.html """This construct uses a irregular syntax (called “list comprehension”) to generate a expression normally built by nested loops. This construct has acquired a incomprehensible name “list comprehension” in computing industry and academia. ... Remember, this jargonized “list comprehension” is nothing more than a irregular syntax for building a list from loops. Its purpose is purely of syntactical convenience. Advanced languages such as functional languages often have this power without the syntax irregularity. (For example, Mathematica's Table function.) """ What was that again about "author masturbation" polluting the documentation, Xah? On Tue, Dec 6, 2011 at 6:13 AM, Rick Johnson wrote: > Listen, python is a great language, but not a perfect one. You people > seem to get all upset at even the slightest suggestion that Python is > not perfect. The haughty arrogance i see day after day around me just > makes me sick. Grow up! You are not perfect and neither is Python... > or Guido for that matter. I don't think Python, Guido, or myself are perfect. I think that most people here don't think that either. Python has its warts. For example, I don't like generator syntax. To be a generator, a function only has to have a "yield" statement somewhere in its body. This is not good self-documenting code. A generator should be clearly marked as such somewhere at the top of the definition. I also think that tacking coroutines onto generators was an ugly hack. Generators an
Re: Python-list Digest, Vol 99, Issue 28
Thanks Steven. Maybe you mean Gnu/Linux when you say Linux. 2011/12/6 : > Send Python-list mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/python-list > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Python-list digest..." > > Today's Topics: > > 1. Re: Python-list Digest, Vol 99, Issue 27 (Sergi Pasoev) > 2. Re: Single key press (alex23) > 3. Re: Single key press (Steven D'Aprano) > 4. Re: struct calcsize discrepency? (Nobody) > 5. Re: Questions about LISP and Python. (Alex Mizrahi) > 6. Re: Backspace does not erase in stdout (Nobody) > 7. Re: Single key press (Hans Mulder) > 8. Re: Single key press (Nobody) > 9. Re: Scope of variable inside list comprehensions? (8 Dihedral) > 10. Re: Scope of variable inside list comprehensions? > (Jean-Michel Pichavant) > > > -- Message transféré -- > From: Sergi Pasoev > To: [email protected] > Date: Tue, 6 Dec 2011 12:59:54 +0430 > Subject: Re: Python-list Digest, Vol 99, Issue 27 > I do not want GUI, I just want a console application which will read a > single character > input. When you read from stdin for example, you have it to be terminated. > > 2011/12/6 : >> Send Python-list mailing list submissions to >> [email protected] >> >> To subscribe or unsubscribe via the World Wide Web, visit >> http://mail.python.org/mailman/listinfo/python-list >> or, via email, send a message with subject or body 'help' to >> [email protected] >> >> You can reach the person managing the list at >> [email protected] >> >> When replying, please edit your Subject line so it is more specific >> than "Re: Contents of Python-list digest..." >> >> Today's Topics: >> >> 1. Re: Questions about LISP and Python. (Xah Lee) >> 2. Re: Questions about LISP and Python. (Chris Angelico) >> 3. Re: 70% [* SPAM *] Re: Re: multiprocessing.Queue blocks when >> sending large object (Dennis Lee Bieber) >> 4. Single key press (Sergi Pasoev) >> 5. Re: Fwd: class print method... (Suresh Sharma) >> 6. Re: Single key press (8 Dihedral) >> 7. Re: Single key press (8 Dihedral) >> 8. Re: Scope of variable inside list comprehensions? (Rainer Grimm) >> 9. Re: Questions about LISP and Python. (alex23) >> 10. Re: Questions about LISP and Python. (Matt Joiner) >> >> >> -- Message transféré -- >> From: Xah Lee >> To: [email protected] >> Date: Mon, 5 Dec 2011 20:36:45 -0800 (PST) >> Subject: Re: Questions about LISP and Python. >> On Dec 5, 4:31 am, Tim Bradshaw wrote: >>> On 2011-12-05 11:51:11 +, Xah Lee said: >>> >>> > python has more readible syntax, more modern computer language >>> > concepts, and more robust libraries. These qualities in turn made it >>> > popular. >>> >>> Yet you still post here: why? >> >> i don't like python, and i prefer emacs lisp. The primary reason is >> that python is not functional, especially with python 3. The python >> community is full of fanatics with their drivels. In that respect, >> it's not unlike Common Lisp community and Scheme lisp community. >> >> see also: >> >> 〈Python Documentation Problems〉 >> http://xahlee.org/perl-python/python_doc_index.html >> >> 〈Computer Language Design: What's List Comprehension and Why is It >> Harmful?〉 >> http://xahlee.org/comp/list_comprehension.html >> >> 〈Lambda in Python 3000〉 >> http://xahlee.org/perl-python/python_3000.html >> >> 〈What Languages to Hate〉 >> http://xahlee.org/UnixResource_dir/writ/language_to_hate.html >> >> 〈Xah on Programing Languages〉 >> http://xahlee.org/Periodic_dosage_dir/comp_lang.html >> >> Xah >> >> >> >> -- Message transféré -- >> From: Chris Angelico >> To: [email protected] >> Date: Tue, 6 Dec 2011 16:10:27 +1100 >> Subject: Re: Questions about LISP and Python. >> On Tue, Dec 6, 2011 at 3:36 PM, Xah Lee wrote: >>> i don't like python, and i prefer emacs lisp. The primary reason is >>> that python is not functional, especially with python 3. The python >>> community is full of fanatics with their drivels. In that respect, >>> it's not unlike Common Lisp community and Scheme lisp community. >> >> So you hate Python. Fine. Why post here? Why not just abandon Python >> as a dead loss and go code in Lithp? >> >> Clearly something is keeping you here. Is it that there's something >> about Python that you really like, or are you just trolling? >> >> ChrisA >> >> >> >> -- Message transféré -- >> From: Dennis Lee Bieber >> To: [email protected] >> Date: Mon, 05 Dec 2011 21:15:09 -0800 >> Subject: Re: 70% [* SPAM *] Re: Re: multiprocessing.Queue blocks
Re: Python 2 or 3
What is the opinion of the wizards here, shall I learm Python 2 or Python 3? I'm posting this here because I feel that this point is interesting to other students of Python. Use the newer version and don't look back. -- http://mail.python.org/mailman/listinfo/python-list
Re: Referring to the class name from a class variable where inheritance is involved
On 06/12/11 15:57, Paul Moore wrote: I want to set up an inheritance hierarchy. The base class will define a string value which should include the class name, but I don't want people who inherit from my class to have to remember to override the value. If I do this using an instance variable, it's reasonably easy: class Base: ... def __init__(self): ... self.key = 'Key_for_' + self.__class__.__name__ ... def display(self): ... print self.key ... class Inherited(Base): ... pass ... b = Base() i = Inherited() b.display() Key_for_Base i.display() Key_for_Inherited Rather than having the key for every instance, I'd like to use a class variable, but I can't see how I'd make that work (a class variable which is inherited but has a different value in derived classes). I could use a classmethod,but that feels like even more overkill than an instance attribute. Is there a way of doing this via class variables or something, or more relevantly, I guess, what would be the idiomatic way of doing something like this? Thanks, Paul You can use a metaclass for this: >>> class BaseMeta(type): ... def __new__(mcs, name, bases, dict): ... dict['key'] = 'Key_for_%s' % name ... return type.__new__(mcs, name, bases, dict) ... >>> class Base: ... __metaclass__ = BaseMeta ... >>> class Inherited(Base): ... pass ... >>> Base.key 'Key_for_Base' >>> Inherited.key 'Key_for_Inheritor' You can find more info on metaclasses here: http://http://docs.python.org/reference/datamodel.html#customizing-class-creation Regards Matt -- http://mail.python.org/mailman/listinfo/python-list
2 or 3 ?
Yes indeed, use the newer version. I thought this problem was already solved, Python 3 has already been there for long enough time. -- http://mail.python.org/mailman/listinfo/python-list
Re: Referring to the class name from a class variable where inheritance is involved
On Tue, Dec 6, 2011 at 8:57 AM, Paul Moore wrote: > I want to set up an inheritance hierarchy. The base class will define > a string value which should include the class name, but I don't want > people who inherit from my class to have to remember to override the > value. > > If I do this using an instance variable, it's reasonably easy: > class Base: > ... def __init__(self): > ... self.key = 'Key_for_' + self.__class__.__name__ > ... def display(self): > ... print self.key > ... class Inherited(Base): > ... pass > ... b = Base() i = Inherited() b.display() > Key_for_Base i.display() > Key_for_Inherited > > Rather than having the key for every instance, I'd like to use a class > variable, but I can't see how I'd make that work (a class variable > which is inherited but has a different value in derived classes). I > could use a classmethod,but that feels like even more overkill than an > instance attribute. > > Is there a way of doing this via class variables or something, or more > relevantly, I guess, what would be the idiomatic way of doing > something like this? How about a class property? class classproperty(object): def __init__(self, fget): self.__fget = fget def __get__(self, instance, owner): return self.__fget(owner) class BaseClass(object): @classproperty def key(cls): return "Key_for_" + cls.__name__ class DerivedClass(BaseClass): pass assert BaseClass.key == BaseClass().key == "Key_for_BaseClass" assert DerivedClass.key == DerivedClass().key == "Key_for_DerivedClass" If you like, you can also expand classproperty to allow setters and deleters like property does. Cheers, Ian -- http://mail.python.org/mailman/listinfo/python-list
Re: Referring to the class name from a class variable where inheritance is involved
On Tue, Dec 6, 2011 at 11:12 AM, Ian Kelly wrote: > If you like, you can also expand classproperty to allow setters and > deleters like property does. My mistake, you can't do this. __set__ and __delete__ are only invoked on instances, not on the class. Get-only class properties are fine, though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 99, Issue 28
12/06/11 11:34, Sergi Pasoev wrote: (after trimming all the digest rubbish the way you should have done in the first place) Coincidentally, I was working on that exact function last night, so you inspired me to put it up on the Python cookbook. This version should work on any POSIX system such as Linux, as well as Windows. I don't know if it will work on Macintosh. http://code.activestate.com/recipes/577977-get-single-keypress/ Thanks Steven. Maybe you mean Gnu/Linux when you say Linux. Sheesh. The guy hands you free code to do what you ask, and 99% of your reply is uselessly-quoted digest, 0.8% is complaining about his terminology, and 0.1% is saying thanks. 1) it's the POSIX API in question here, nothing particularly GNU about the Linux implementation of it. 2) if you want to be pedantic about it, you should really be calling such systems something like Xorg/[Gnome|KDE|Fluxbox|LXDE|OpenBox|BlackBox|FVWM|XFCE]/Linux/GNU/Mozilla/TeX/MySQL/Postgresql/sqlite/git/CVS/Subversion/Bazaar/Mercurial/Python/Perl/PHP/Apache. And why don't you call it that? Because it's a pain, and if you say "Linux" everybody knows that you're talking about an operating system that uses Linux and has other contributions in it. So I'm pretty sure that Steven did *not* mean to type "GNU/Linux" or he would have typed it that way. :) -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Referring to the class name from a class variable where inheritance is involved
On 6 December 2011 18:12, Ian Kelly wrote: > How about a class property? > > class classproperty(object): > def __init__(self, fget): > self.__fget = fget > def __get__(self, instance, owner): > return self.__fget(owner) Nice :-) About as heavyweight as a classmethod, though, so it doesn't buy me much over that (beyond avoiding a set of parens, which isn't a big deal). Either classmethod or classproperty gives me the key benefit I'm after, which is avoiding the per-instance overhead, though. TBH, this is a huge case of premature optimisation, though, so it's probably little more than an academic or style question. :-) Paul -- http://mail.python.org/mailman/listinfo/python-list
Multiprocessing bug, is my editor (SciTE) impeding my progress?
Hi, folks, Back in 2002, I got back into programming after a nine-year hiatus. I needed a new programming language, was guided to Python 2.2, and was off to the races. I chose the SciTE program editor, and I have been using it ever since. I'm now using Python 2.6 on Ubuntu Linux 10.10. My programming needs have grown more sophisticated, but I'm still using SciTE. Pretty much all of my recent posts to comp.lang.python have concerned multiprocessing. I put together a decent system for my current project, and had it all working. Then I realized that I needed to refactor and expand some code, which I did -- and somehow, I generated a bug that I simply cannot understand. I've been puzzling over it for three days. The error is occurring inside one of my subprocesses. As far as I know, SciTE is limited in what it can do in this situation. The program does not return when a subprocess generates an exception. I see the error message, but then the program simply hangs. I have tried invoking the subprocess directly without scheduling it through multiprocessing.Pool. It works fine. So the problem is occurring inside Pool. I tried opening my code in IDLE, and figured I could step through it, or at least call functions one line at a time. It appears that multiprocessing code is not compatible with IDLE. IDLE simply crashes when I try to invoke any of the important functions. I know, you want me to post a minimal example. Most of the time, that's possible, and I do it. Trust me, this time it isn't. I have about 500 lines of code, split across three files. These implement a neural network, some test data, and multiprocessing methods for network evaluation. I made several concerted changes to the code, and turned a working system into this: = Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 484, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) TypeError: expected string or Unicode object, NoneType found = Here's what I think would help me debug this error: I would like to catch the TypeError, and examine the contents of task. I need to accomplish this WITHOUT adding a try...except block to the Python library file multiprocessing/pool.py. I don't know whether this is possible, because the traceback isn't clear about where my OWN code calls the code which is generating the error. After that, if the cause of the error still is not obvious, I might need to go back to the working program. Somehow I want to examine the contents of task when the program works, and no TypeError is being generated. By comparing the two, I hope to see a difference. From that, I should be able to figure out how I have broken what is being fed to Pool.__init__ and/or MapResult.__init__. Any suggestions how I might best accomplish this task? Does this error message look familiar to anyone? More generally, should I consider graduating from SciTE? I have had a look at a few of the more comprehensive IDE's over the years, and I'll have to say that I found them to be intimidating. I found it to be a huge chore just to open a single Python script and run it inside an IDE. It seems like you had to know how to set up a complete, multi- script project before you could even accomplish simple tasks. That steep learning curve is the reason that I didn't choose Java as my programming language. So, if any of you have pertinent recommendations in the IDE department, please feel free to guide me that way. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: why is bytearray treated so inefficiently by pickle?
On a related note, pickling of arrays of float64 objects, as generated by the numpy package for example, are wildly inefficient with memory. A half-million float64's requires about 4 megabytes, but the pickle file I generated from a numpy.ndarray of this size was 42 megabytes. I know that numpy has its own pickle protocol, and that it's supposed to help with this problem. Still, if this is a general problem with Python and pickling numbers, it might be worth solving it in the language itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: Referring to the class name from a class variable where inheritance is involved
On Dec 6, 5:29 pm, Matt Saxton wrote: > You can use a metaclass for this: > > >>> class BaseMeta(type): > ... def __new__(mcs, name, bases, dict): > ... dict['key'] = 'Key_for_%s' % name > ... return type.__new__(mcs, name, bases, dict) > ... > >>> class Base: > ... __metaclass__ = BaseMeta > ... > >>> class Inherited(Base): > ... pass > ... > >>> Base.key > 'Key_for_Base' > >>> Inherited.key > 'Key_for_Inheritor' I like that! I tend to think of metaclasses as for "complicated" stuff. It's nice to see a simple use. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Clever hack or code abomination?
On Dec 1, 12:21 am, Chris Angelico wrote: > On Thu, Dec 1, 2011 at 2:15 PM, Roy Smith wrote: > That's a self-contained piece of code.If I came upon it, I'd probably > copy and paste it to IDLE, see what it comes up with, and proceed from > there. +1. That was going to be my comment exactly. -- http://mail.python.org/mailman/listinfo/python-list
Re: why is bytearray treated so inefficiently by pickle?
On 06-12-11 20:27, John Ladasky wrote: On a related note, pickling of arrays of float64 objects, as generated by the numpy package for example, are wildly inefficient with memory. A half-million float64's requires about 4 megabytes, but the pickle file I generated from a numpy.ndarray of this size was 42 megabytes. I know that numpy has its own pickle protocol, and that it's supposed to help with this problem. Still, if this is a general problem with Python and pickling numbers, it might be worth solving it in the language itself. Python provides ample ways for custom types to influence the way they're pickled (getstate/setstate, reduce). Are numpy's arrays are pickled similar to Python's own array types? In that case, when using Python 2.x, they're pickled very inefficiently indeed (every element is encoded with its own token). In Python 3.x, array pickling is very efficient because it stores the machine type representation in the pickle. Irmen -- http://mail.python.org/mailman/listinfo/python-list
Re: why is bytearray treated so inefficiently by pickle?
On 12/6/11 7:27 PM, John Ladasky wrote: On a related note, pickling of arrays of float64 objects, as generated by the numpy package for example, are wildly inefficient with memory. A half-million float64's requires about 4 megabytes, but the pickle file I generated from a numpy.ndarray of this size was 42 megabytes. I know that numpy has its own pickle protocol, and that it's supposed to help with this problem. Still, if this is a general problem with Python and pickling numbers, it might be worth solving it in the language itself. It is. Use protocol=HIGHEST_PROTOCOL when dumping the array to a pickle. [~] |1> big = np.linspace(0.0, 1.0, 50) [~] |2> import cPickle [~] |3> len(cPickle.dumps(big)) 11102362 [~] |4> len(cPickle.dumps(big, protocol=cPickle.HIGHEST_PROTOCOL)) 4000135 The original conception for pickle was that it would have an ASCII representation for optimal cross-platform compatibility. These were the days when people still used FTP regularly, and you could easily (and silently!) screw up binary data if you sent it in ASCII mode by accident. This necessarily creates large files for numpy arrays. Further iterations on the pickling protocol let numpy use raw binary data in the pickle. However, for backwards compatibility, the default protocol is the one Python started out with. If you explicitly use the most recent protocol, then you will get the efficiency benefits. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On Dec 6, 8:13 pm, John Ladasky wrote: > Hi, folks, > > Back in 2002, I got back into programming after a nine-year hiatus. I > needed a new programming language, was guided to Python 2.2, and was > off to the races. I chose the SciTE program editor, and I have been > using it ever since. I'm now using Python 2.6 on Ubuntu Linux 10.10. > > My programming needs have grown more sophisticated, but I'm still > using SciTE. Pretty much all of my recent posts to comp.lang.python > have concerned multiprocessing. I put together a decent system for my > current project, and had it all working. Then I realized that I > needed to refactor and expand some code, which I did -- and somehow, I > generated a bug that I simply cannot understand. I've been puzzling > over it for three days. > > The error is occurring inside one of my subprocesses. As far as I > know, SciTE is limited in what it can do in this situation. The > program does not return when a subprocess generates an exception. I > see the error message, but then the program simply hangs. > > I have tried invoking the subprocess directly without scheduling it > through multiprocessing.Pool. It works fine. So the problem is > occurring inside Pool. > > I tried opening my code in IDLE, and figured I could step through it, > or at least call functions one line at a time. It appears that > multiprocessing code is not compatible with IDLE. IDLE simply crashes > when I try to invoke any of the important functions. > > I know, you want me to post a minimal example. Most of the time, > that's possible, and I do it. Trust me, this time it isn't. I have > about 500 lines of code, split across three files. These implement a > neural network, some test data, and multiprocessing methods for > network evaluation. I made several concerted changes to the code, and > turned a working system into this: > > = > > Exception in thread Thread-1: > Traceback (most recent call last): > File "/usr/lib/python2.6/threading.py", line 532, in > __bootstrap_inner > self.run() > File "/usr/lib/python2.6/threading.py", line 484, in run > self.__target(*self.__args, **self.__kwargs) > File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > _handle_tasks > put(task) > TypeError: expected string or Unicode object, NoneType found > > = > > Here's what I think would help me debug this error: I would like to > catch the TypeError, and examine the contents of task. I need to > accomplish this WITHOUT adding a try...except block to the Python > library file multiprocessing/pool.py. I don't know whether this is > possible, because the traceback isn't clear about where my OWN code > calls the code which is generating the error. > > After that, if the cause of the error still is not obvious, I might > need to go back to the working program. Somehow I want to examine the > contents of task when the program works, and no TypeError is being > generated. By comparing the two, I hope to see a difference. From > that, I should be able to figure out how I have broken what is being > fed to Pool.__init__ and/or MapResult.__init__. > > Any suggestions how I might best accomplish this task? Does this > error message look familiar to anyone? > > More generally, should I consider graduating from SciTE? I have had a > look at a few of the more comprehensive IDE's over the years, and I'll > have to say that I found them to be intimidating. I found it to be a > huge chore just to open a single Python script and run it inside an > IDE. It seems like you had to know how to set up a complete, multi- > script project before you could even accomplish simple tasks. That > steep learning curve is the reason that I didn't choose Java as my > programming language. > > So, if any of you have pertinent recommendations in the IDE > department, please feel free to guide me that way. > > Thanks! Hello John, One way of trying to debug the issue could be to use ipython and ipdb. You cadn than run your code from within the ipython shell. The debugger will hold at the type error, but keep the context. At this point you should be able to evaluate task. As a side comment to your IDE remarks. I keep switching between VIM and Aptana/Pydev. The more I learn about VIM the more I feel comfortable and productive. In combination with ipython it is quite a solid development environment. On the other hand Pydev is very user friendly, powerfull and easy to learn. Debugging in Pydev is excellent. Regards, Marco -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On 12/6/2011 2:13 PM, John Ladasky wrote: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/usr/lib/python2.6/threading.py", line 484, in run self.__target(*self.__args, **self.__kwargs) File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in _handle_tasks put(task) TypeError: expected string or Unicode object, NoneType found = Here's what I think would help me debug this error: I would like to catch the TypeError, and examine the contents of task. The traceback says that it is None, which has no contents ;=). I need to accomplish this WITHOUT adding a try...except block to the Python library file multiprocessing/pool.py. I do not understand this statement. You should feel free to make a backup copy of pool.py and then modify it for debugging. > I don't know whether this is possible, because the traceback isn't clear about where my OWN code calls the code which is generating the error. It appears to be threading trying to call your code, and failing, that is the problem. But I do not know how threading, multiprocessing.pool, and your code are supposed to interact. After that, if the cause of the error still is not obvious, I might need to go back to the working program. Somehow I want to examine the contents of task when the program works, and no TypeError is being generated. The traceback says that it is a string. I would start with the line that fails 'put(task)', and work backwards to see where 'task' comes from and how it could become None. It is even possible that multiprocessing.pool has a bug that you ran into. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: the deceptive continuous assignments
On 12/6/2011 7:33 AM, Chris Angelico wrote:
On Tue, Dec 6, 2011 at 11:20 PM, Terry Reedy wrote:
You found an unsafe overlap.
x.thing = x = 1
would work, though it seems strange (and unlikely in practice) to rebind x
to an int after it is bound to a class k instance.
This code is starting to look like it wants to work with a linked list.
class node:
def __init__(self,x):
self.payload=x
self.next=None
def walk(self):
print("My payload is: "+self.payload)
if self.next: self.next.walk()
head=tail=node("This")
tail.next=tail=node("is")
tail.next=tail=node("a")
tail.next=tail=node("test.")
head.walk()
My payload is: This
My payload is: is
My payload is: a
My payload is: test.
Cute. I am used to linked lists being built from the bottem up in
functional languages with immutable nodes. I might even use something
like this. Of course, for a list of any length, walk needs to be iterative.
def walk(self):
while self:
print("My payload is: "+self.payload)
self = self.next
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
Re: the deceptive continuous assignments
On Wed, Dec 7, 2011 at 9:11 AM, Terry Reedy wrote:
> Cute. I am used to linked lists being built from the bottem up in functional
> languages with immutable nodes. I might even use something like this. Of
> course, for a list of any length, walk needs to be iterative.
>
> def walk(self):
> while self:
>
> print("My payload is: "+self.payload)
> self = self.next
Of course, but I was coding top-down and didn't feel like going back
to add the "while" :)
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Re: why is bytearray treated so inefficiently by pickle?
On Nov 30, Irmen de Jong opened a tracker issue with a patch improve bytearray pickling. http://bugs.python.org/issue13503 Yesterday, Dec 5, Antoine Pitrou applied a revised fix. http://hg.python.org/cpython/rev/e2959a6a1440/ The commit message: "Issue #13503: Use a more efficient reduction format for bytearrays with pickle protocol >= 3. The old reduction format is kept with older protocols in order to allow unpickling under Python 2." -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
Thanks, Marco. I've noticed that the matplotlib reference manual recommends ipython. I haven't been clear what its advantages are, but if interacting with multiprocessing correctly is one of them, I'll try it. If ipython does everything that IDLE does and more, why is IDLE still shipped with Python anyway? I'll follow up on your IDE recommendations too after trying ipython. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
John I'm in a similar position. I've been using Geany for 2+ years and haven't found anything to replace it. Either the replacement tool makes it too difficult to work with Python correctly, or I spend more time trying to understand it, rather than getting the job done. I also use vim on occasion when GUI isn't an option. I seem to do okay, so I'm not sure you're at any disadvantage. A stand alone graphical debugger would be handy tho... On Wed, Dec 7, 2011 at 11:17 AM, John Ladasky wrote: > Thanks, Marco. > > I've noticed that the matplotlib reference manual recommends ipython. > I haven't been clear what its advantages are, but if interacting with > multiprocessing correctly is one of them, I'll try it. > > If ipython does everything that IDLE does and more, why is IDLE still > shipped with Python anyway? > > I'll follow up on your IDE recommendations too after trying ipython. > -- > http://mail.python.org/mailman/listinfo/python-list -- ಠ_ಠ -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On Dec 6, 1:42 pm, Terry Reedy wrote: > On 12/6/2011 2:13 PM, John Ladasky wrote: > > Exception in thread Thread-1: > > Traceback (most recent call last): > > File "/usr/lib/python2.6/threading.py", line 532, in > > __bootstrap_inner > > self.run() > > File "/usr/lib/python2.6/threading.py", line 484, in run > > self.__target(*self.__args, **self.__kwargs) > > File "/usr/lib/python2.6/multiprocessing/pool.py", line 225, in > > _handle_tasks > > put(task) > > TypeError: expected string or Unicode object, NoneType found > > > = > > > Here's what I think would help me debug this error: I would like to > > catch the TypeError, and examine the contents of task. > > The traceback says that it is None, which has no contents ;=). I'm not sure about that. I don't submit the task variable, it's something that Pool builds from what I submit. Is task == None when it should be a string? Or, is task an iterable which contains one element which should be a string? And what's supposed to be in that string anyway? My first reading of the source code of Pool didn't make this clear to me. Also, I've noticed that tracebacks from subprocesses are less informative than tracebacks from the parent process. What's missing? Finally, I also recall that multiprocessing invokes pickle to pass data between processes (I still don't understand the need for pickle here). This suggests to me that the string MIGHT contain the pickled code of the method I want to run in the subprocess. But I'm not sure, until I can actually examine the task variable in my working version. > > I need to > > accomplish this WITHOUT adding a try...except block to the Python > > library file multiprocessing/pool.py. > > I do not understand this statement. You should feel free to make a > backup copy of pool.py and then modify it for debugging. Right, so, the last time I tried this with a piece of library code, I ran into some major headaches with import statements. I suppose I could have a look at Pool and see whether it can be extracted cleanly and made to run. > > I don't know whether this is > > > possible, because the traceback isn't clear about where my OWN code > > calls the code which is generating the error. > > It appears to be threading trying to call your code, and failing, that > is the problem. But I do not know how threading, multiprocessing.pool, > and your code are supposed to interact. It might be that pickle has somehow managed to pass a null code string to the subprocess, so it has nothing to run. > > After that, if the cause of the error still is not obvious, I might > > need to go back to the working program. Somehow I want to examine the > > contents of task when the program works, and no TypeError is being > > generated. > > The traceback says that it is a string. Yes, again... I want to know what that string is supposed to DO. > I would start with the line that fails 'put(task)', and work backwards > to see where 'task' comes from and how it could become None. It is even > possible that multiprocessing.pool has a bug that you ran into. Oh, please don't say that. I'm no computer scientist, and Python has been scrutinized by so many professionals. I couldn't have possibly found a language bug. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On 12/6/2011 7:30 PM, John Ladasky wrote: On Dec 6, 1:42 pm, Terry Reedy wrote: On 12/6/2011 2:13 PM, John Ladasky wrote: I need to accomplish this WITHOUT adding a try...except block to the Python library file multiprocessing/pool.py. I do not understand this statement. You should feel free to make a backup copy of pool.py and then modify it for debugging. Right, so, the last time I tried this with a piece of library code, I ran into some major headaches with import statements. I suppose I could have a look at Pool and see whether it can be extracted cleanly and made to run. I have patched files both in /Lib and /Lib/idle on Windows with no problems except that I had to switch to admin account to make the patch. I probably changed 'copy of x.py' to either 'x.bak' or 'x.py.bak' but I do not remember. Deleting .pyc might or might not help. For a file in Lib, I have also copied to the working directory with my script, which gets prepended to sys.path. This makes restoring the default easier. One would have to copy all of multiprocessing/ for that to work with m.../pool.py. -- Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 99, Issue 28
On Tue, 06 Dec 2011 22:04:36 +0430, Sergi Pasoev wrote: > Thanks Steven. Maybe you mean Gnu/Linux when you say Linux. Maybe I do, maybe I don't. Since you're replying to a digest and neither adjusted the subject line nor trimmed almost a dozen pages of unnecessary quoted text, I have no idea what you are referring to, or whether you are replying to me or some other Steven. -- Steven but perhaps not the right Steven -- http://mail.python.org/mailman/listinfo/python-list
Hints for writing bit-twiddling code in Python
I have some bit-twiddling code written in Java which I am trying to port
to Python. I'm not getting the same results though, and I think the
problem is due to differences between Java's signed byte/int/long types,
and Python's unified long integer type. E.g. Java's >>> is not exactly
the same as Python's >> operator, and a character coerced to a byte in
Java is not the same as ord(char) in Python. (The Java byte is in the
range -128...127, I think, while the ord in Python is in 0...255.)
Can anyone point me to some good resources to help me port the Java code
to Python?
If it helps, the Java code includes bits like this:
long newSeed = (seed & 0xL) * 0x41A7L;
while (newSeed >= 0x8000L) {
newSeed = (newSeed & 0x7FFFL) + (newSeed >>> 31L);
}
seed = (newSeed == 0x7FFFL) ? 0 : (int)newSeed;
which I've translated into:
newseed = (seed & 0x)*0x41A7
while (newseed >= 0x8000):
newseed = (newseed & 0x7FFF) + (newseed >> 31)
seed = 0 if newseed == 0x7FFF else newseed & 0x
--
Steven
--
http://mail.python.org/mailman/listinfo/python-list
Re: order independent hash?
On Monday, December 5, 2011 7:24:49 AM UTC+8, Ian wrote: > On Sun, Dec 4, 2011 at 4:17 PM, 8 Dihedral > wrote: > >> Please explain what you think a hash function is, then. Per > >> Wikipedia, "A hash function is any algorithm or subroutine that maps > >> large data sets to smaller data sets, called keys." > >> > >> > Are you miss-leading the power of true OOP ? > >> > >> I have no idea what you are suggesting. I was not talking about OOP at > >> all. > > > > In python the (k,v) pair in a dictionary k and v can be both an objects. > > v can be a tuple or a list. There are some restrictions on k to be an > > hashable type in python's implementation. The key is used to compute the > > position of the pair to be stored in a hash table. The hash function maps > > key k to the position in the hash table. If k1!=k2 are both mapped to the > > same > > position, then something has to be done to resolve this. > > I understand how dicts / hash tables work. I don't need you to > explain that to me. What you haven't explained is why you stated that > a hash function that operates on objects is not a hash function, or > what you meant by "misleading the power of true OOP". Do you forget the memory management of a dictionary in Python that has to be linked for a dynamical growing and shrinking number of (k,v) pairs in a long period of time? Avoiding the true non-trivial part in any implementation or use of a dictionary is miss leading ? Probing too deep in the stack or occupying too much in the heap is not bug free? -- http://mail.python.org/mailman/listinfo/python-list
Re: Hints for writing bit-twiddling code in Python
On 12/6/11, Steven D'Aprano wrote:
> I have some bit-twiddling code written in Java which I am trying to port
> to Python.:
>
> long newSeed = (seed & 0xL) * 0x41A7L;
> while (newSeed >= 0x8000L) {
> newSeed = (newSeed & 0x7FFFL) + (newSeed >>> 31L);
> }
> seed = (newSeed == 0x7FFFL) ? 0 : (int)newSeed;
I suspect the problem lies somewhere other than the java and python
code you posted.
I'm having a bit of a time finding an input value of seed that gives
two different results, despite throwing some hard-feeling test cases
and lots of random values, using both a 32 bit and a 64 bit JVM.
I believe java likes to treat strings like Python 3, but if you use
"export LC_ALL=en_US.ISO-8859-1", then it'll behave a little more like
Python 2 in that strings have an 8 bit encoding (or at least act like
it) that's round-tripable.
If worse comes to worse, you could probably write some test harness
code for each of the java and python, and then feed them the same
inputs - to see which pieces differ and which don't.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On Tue, 06 Dec 2011 16:30:16 -0800, John Ladasky wrote: >> I would start with the line that fails 'put(task)', and work backwards >> to see where 'task' comes from and how it could become None. It is even >> possible that multiprocessing.pool has a bug that you ran into. > > Oh, please don't say that. I'm no computer scientist, and Python has > been scrutinized by so many professionals. I couldn't have possibly > found a language bug. "Professional" just means they get paid for doing it. Professionals gave us the 2008 banking collapse, the Challenger shuttle explosion, the sinking of the Titanic, trench warfare in World War I, the Chernobyl nuclear meltdown, leaded petrol, "Battlefield Earth" the movie, and the BP Gulf of Mexico oil spill. Amateurs gave us the discovery of electricity, the Roomba, the original Apple computer, GNU software, Linux, Ogg/Vorbis, and the discovery of continental drift. While your modesty is a welcome change from n00bs who imagine that anything about Python that they misunderstood is a bug, don't sell yourself short. You don't need to be a computer scientist to identify bugs in software. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On Wed, Dec 7, 2011 at 5:57 PM, Steven D'Aprano wrote: > On Tue, 06 Dec 2011 16:30:16 -0800, John Ladasky wrote: > >> Oh, please don't say that. I'm no computer scientist, and Python has >> been scrutinized by so many professionals. I couldn't have possibly >> found a language bug. > > While your modesty is a welcome change from n00bs who imagine that > anything about Python that they misunderstood is a bug, don't sell > yourself short. You don't need to be a computer scientist to identify > bugs in software. Likelihood of something being a bug generally depends heavily on "eyeball density". If a piece of code gets a lot of eyeballs, chances are its bugs have been found (not always but often). Generally, the code that makes up a heavily-used open source project can be expected to have quite a few eyeballs near it as a regular thing; but there's always the obscure bits that don't. Crypto modules have fallen foul of this on occasion, with bugs lurking there far more than might otherwise be expected, on account of such a small portion of coders ever touching cryptography. Of course, it's always less embarrassing to say "I think I'm using this wrong" and have someone say "You found a language bug" than to come in guns blazing with "ur lnguage is teh buggy" (sorry, I don't speak Lame very fluently) only to learn that you spoiled the incantation in some way. The number of people who assume that their first-time code is perfect and the language is hopeless is somewhat astonishing. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiprocessing bug, is my editor (SciTE) impeding my progress?
On Dec 6, 7:30 pm, John Ladasky wrote: > On Dec 6, 1:42 pm, Terry Reedy wrote: > > It is even possible that multiprocessing.pool has a bug > > that you ran into. > > Oh, please don't say that. I'm no computer scientist, and > Python has been scrutinized by so many professionals. I > couldn't have possibly found a language bug. Scrutiny or no, Python has its fair share of bugs. I think almost all real-world implementations of almost all general-purpose programming languages do. Not long ago a friend of mine (a mathematician, but only a novice programmer) sent me some code dealing with sets that exposed a bug in Python 2.6.1. He invoked the union() method from the set class rather than a set instance, and it took us a long time to figure out why he was getting different results than I was from the same code (I was the one on 2.6.1, and my results were wrong). Fortunately, it was (a) easy enough to work around and (b) fixed in subsequent versions of Python. But it just goes to show that even unsophisticated programmers can stumble upon language bugs. This one wasn't even in the library; it was a built-in. That hasn't shaken my confidence in Python, though. (Also, for what it's worth, I use SciTE as my Python editor as well. I've also used Geany from time to time, and I have no trouble recommending it. It's a step up the IDE ladder from SciTE, but is still tons lighter than Eclipse and its brethren.) John -- http://mail.python.org/mailman/listinfo/python-list
