Re: Spreadsheet-style dependency tracking
On Oct 19, 8:59 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message eeb52362-1308-4c3f-85a2-7493f796a...@g18g2000yqk.googlegroups.com, Carl Banks wrote: On Oct 18, 4:15 pm, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote: In message 42d82f8a-4ee6-44a7-914d-86dfc21f1...@a36g2000yqc.googlegroups.com, Fuzzyman wrote: Allowing calculations to complete even in the presence of cycles can be very useful. But then the answer is no longer completely deterministic. Yes it is ... No, because it will change depending on the iteration number. And if the computation doesn’t converge, this is a recipe for oscillations, including chaotic ones. Go look up deterministic in Wikipedia. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: OO and game design questions
On Oct 19, 8:08 pm, Carl Banks pavlovevide...@gmail.com wrote: On Oct 19, 1:19 am, dex josipmisko...@gmail.com wrote: I'm not sure if it's a good idea to let an item disappear from your inventory by a weak reference disappearing. It seems a little shaky to not know where your objects are being referenced, but that's yout decision. OK, imagine a MUD, where players can dig out new rooms. Room A has a door that holds reference to newly created room B. By using a door, player is transported to room B. At later time someone destroys room B. Using strong references, I have to remove room B from list of rooms, and also remove door to room B, as it holds reference to room B. To do that, I have to keep list of doors that lead to room B. Using weak references, I don't have to worry about removing all doors to room B. They all now have a dead reference, which better models actual situation. If part of mine collapses, or if a module on space station is destroyed, the passage to that location does not magically vanish - it's just obstructed. Can you please tell me if there's something wrong with my reasoning? Well, you're talking about particulars here whereas I am speaking in general. If something is questionable or even bad in general it doesn't mean there are no particular cases for it. Generally speaking: in a game there's presumably some conservation of objects. If you drop an item, does it disappear, or does it become an object of the room? Weak referencing won't help you in the latter case because you have to take care of references at both ends anyway. That's what I mean by shaky: it lets you forget about half of the transaction, which might not be the best thing. YMMV Carl Banks I see your point. I'll think this through and try to build more robust system. Thanks for your insight. -- http://mail.python.org/mailman/listinfo/python-list
Re: OO and game design questions
On Oct 19, 6:54 pm, Dennis Lee Bieber wlfr...@ix.netcom.com wrote: On Tue, 19 Oct 2010 01:19:48 -0700 (PDT), dex josipmisko...@gmail.com declaimed the following in gmane.comp.python.general: OK, imagine a MUD, where players can dig out new rooms. Room A has a door that holds reference to newly created room B. By using a door, player is transported to room B. At later time someone destroys room B. Out of curiosity, have you looked at any of the older Python efforts? http://py-universe.sourceforge.net/http://www.strout.net/info/coding/python/poo/index.html(some dead links) -- Wulfraed Dennis Lee Bieber AF6VN wlfr...@ix.netcom.com HTTP://wlfraed.home.netcom.com/ I will check out your links. I did some research on several MUD projects (evennia, PyMUD) and gained very little from them. I used MUD only as example, my game idea is combination of Rogue and Elite, with Darklands GUI. It's definitely overambitious, but I'm taking it slowly and learning things on the way. Thanks for input. -- http://mail.python.org/mailman/listinfo/python-list
Re: merge list of tuples with list
On Wed, Oct 20, 2010 at 1:33 PM, Daniel Wagner brocki2...@googlemail.com wrote: Any more efficient ways or suggestions are still welcome! In article mailman.58.1287547882.2218.python-l...@python.org James Mills prolo...@shortcircuit.net.au wrote: Did you not see Paul Rubin's solution: [x+(y,) for x,y in zip(a,b)] [(1, 2, 3, 7), (4, 5, 6, 8)] I think this is much nicer and probably more efficient. For a slight boost in Python 2.x, use itertools.izip() to avoid making an actual list out of zip(a,b). (In 3.x, plain zip() is already an iterator rather than a list-result function.) This method (Paul Rubin's) uses only a little extra storage, and almost no extra when using itertools.izip() (or 3.x). I think it is more straightforward than multi-zip-ing (e.g., zip(*zip(*a) + [b])) as well. The two-zip method needs list()-s in 3.x as well, making it clearer where the copies occur: list(zip(*a)) makes the list [(1, 4), (2, 5), (3, 6)] [input value is still referenced via a so sticks around] [b] makes the tuple (7, 8) into the list [(7, 8)] [input value is still referenced via b so sticks around] + adds those two lists producing the list [(1, 4), (2, 5), (3, 6), (7, 8)] [the two input values are no longer referenced and are thus discarded] list(zip(*that)) makes the list [(1, 2, 3, 7), (4, 5, 6, 8)] [the input value -- the result of the addition in the next to last step -- is no longer referenced and thus discarded] All these temporary results take up space and time. The list comprehension simply builds the final result, once. Of course, I have not used timeit to try this out. :-) Let's do that, just for fun (and to let me play with timeit from the command line): (I am not sure why I have to give the full path to the timeit.py source here) sh-3.2$ python /System/Library/Frameworks/Python.framework/\ Versions/2.5/lib/python2.5/timeit.py \ 'a=[(1,2,3),(4,5,6)];b=(7,8);[x+(y,) for x,y in zip(a,b)]' 10 loops, best of 3: 2.55 usec per loop sh-3.2$ python [long path snipped] \ 'a=[(1,2,3),(4,5,6)];b=(7,8);[x+(y,) for x,y in zip(a,b)]' 10 loops, best of 3: 2.56 usec per loop sh-3.2$ python [long path snipped] \ 'a=[(1,2,3),(4,5,6)];b=(7,8);zip(*zip(*a) + [b])' 10 loops, best of 3: 3.84 usec per loop sh-3.2$ python [long path snipped] \ 'a=[(1,2,3),(4,5,6)];b=(7,8);zip(*zip(*a) + [b])' 10 loops, best of 3: 3.85 usec per loop Hence, even in 2.5 where zip makes a temporary copy of the list, the list comprehension version is faster. Adding an explicit use of itertools.izip does help, but not much, with these short lists: sh-3.2$ python ... -s 'import itertools' \ 'a=[(1,2,3),(4,5,6)];b=(7,8);[x+(y,) for x,y in itertools.izip(a,b)]' 10 loops, best of 3: 2.27 usec per loop sh-3.2$ python ... -s 'import itertools' \ 'a=[(1,2,3),(4,5,6)];b=(7,8);[x+(y,) for x,y in itertools.izip(a,b)]' 10 loops, best of 3: 2.29 usec per loop (It is easy enough to move the assignments to a and b into the -s argument, but it makes relatively little difference since the list comprehension and two-zip methods both have the same setup overhead. The import, however, is pretty slow, so it is not good to repeat it on every trip through the 10 loops -- on my machine it jumps to 3.7 usec/loop, almost as slow as the two-zip method.) -- In-Real-Life: Chris Torek, Wind River Systems Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603 email: gmail (figure it out) http://web.torek.net/torek/index.html -- http://mail.python.org/mailman/listinfo/python-list
Python debug assertion
Python disables MSCRT assertions for debug mode in the initialization of exceptions module. Does anyone know why? -- http://mail.python.org/mailman/listinfo/python-list
Re: merge list of tuples with list
Daniel Wagner wrote: Hello Everyone, I'm new in this group and I hope it is ok to directly ask a question. My short question: I'm searching for a nice way to merge a list of tuples with another tuple or list. Short example: a = [(1,2,3), (4,5,6)] b = (7,8) After the merging I would like to have an output like: a = [(1,2,3,7), (4,5,6)] It was possible for me to create this output using a for i in a technique but I think this isn't a very nice way and there should exist a solution using the map(), zip()-functions I appreciate any hints how to solve this problem efficiently. from itertools import starmap, izip from operator import add a = [(1,2,3), (4,5,6)] b = (7,8) list(starmap(add, izip(a, izip(b [(1, 2, 3, 7), (4, 5, 6, 8)] This is likely slower than the straightforward [x + (y,) for x, y in zip(a, b)] for short lists, but should be faster for long lists. Of course you'd have to time-it to be sure. You should also take into consideration that the latter can be understood immediately by any moderately experienced pythonista. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading Outlook .msg file using Python
On 19/10/2010 22:48, John Henry wrote: Looks like this flag is valid only if you are getting messages directly from Outlook. When reading the msg file, the flag is invalid. Same issue when accessing attachments. In addition, the MAPITable method does not seem to work at all when trying to get attachments out of the msg file (works when dealing with message in an Outlook mailbox). Eitherway, the display_name doesn't work when trying to display the filename of the attachment. I was able to get the date by using the PR_TRANSPORT_MESSAGE_HEADERS mapitags Ah, thanks. As you will have realised, my code is basically geared to reading an Outlook/Exchange message box. I hadn't really tried it on individual message files, except my original excerpt. If it were opportune, I'd be interested in seeing your working code. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: Python-on-a-Chip release 09
dwhall, 18.10.2010 15:15: Python-on-a-Chip Featuring the PyMite VM === [...] Python-on-a-Chip (p14p) is a project to develop a reduced Python virtual machine (codenamed PyMite) that runs a significant subset of the Python language on microcontrollers without an OS. Do you have any idea of how fast it is compared to CPython when run on a normal CPU? Given the size indications of a few KB of required memory, the entire runtime should easily fit into a couple of cache lines of the CPU's L1 cache, which could be quite an advantage, at least for selected use cases. I assume it also uses unboxed (plain integer/float) arithmetic, right? Does that make a difference? Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: OO and game design questions
On Oct 18, 8:28 am, dex josipmisko...@gmail.com wrote: I'm building a turn based RPG game as a hobby. The design is becoming increasingly complicated and confusing, and I think I may have tendency to over-engineer simple things. Can anybody please check my problems-solutions and point me to more elegant solution? Every item/character/room is a separate object. Items/characters need to have references to room they are in, and room needs to have a list of references to items/characters that are contained within. I decided to use weak references. That way I can destroy object by deleting it, I don't have to destroy all references as well. In each object's __init__() that object is added to game_object list, and in each __del__() they are removed from game_object list. This mechanism keeps them safe from garbage collector. How pythonic is this design? In turn-based games, the order of action execution in battle can give unfair advantage to players. For example, if player's arm is crippled before his action is executed, he would do less damage. To offset this, I first execute all players' actions and calculate effects in first pass, then apply the effects in second pass. The effect can be health decrease by 15HP, item pick-up, 30p experience gain, etc. This means the player deals the same amount of damage no matter what happens to him in that turn. The difficult part is keeping track of various effects. I had to make separate class for various types of effects (ChangeAttributeEffect, GetItemEffect, LooseItemEffect). Each class stores weak reference to target object and has apply() method that applies the effect to object. I'm not satisfied with this as it's limiting, error-prone and uses metaprogramming. Is there a design pattern that would remember changes to an object, and apply them later? Sorry for the wall of text. One common way to store delayed actions is as a lambda (an anonymous function.) A lambda defines a new function: , and you can call this function later. The created function has no name, (but you can assign it to a variable to give it a name if you like) and can be called later: So in the game, you could have a collection 'effects', each one will be a lambda: effects = [] At the start of the round, as each entity makes its moves, they add lambdas to this collection. effects.append( lambda: decrease_hp(monster_a, 4) ) effects.append( lambda: lose_item(monster_a, item_b) ) Instead of appending it directly like this, I imagine the lambdas could be returned by the monster's 'act' or 'update' method: class Monster(): def act(self): # blah and finally return lambda: decrease_hp(monster_a, 4) Then for the start of a round, first you ask each monster what action it is going to perform: for monster in room.monsters: effects.append( monster.act() ) Then for the end of the round, call all the lambdas for effect in effects: effect() -- http://mail.python.org/mailman/listinfo/python-list
Re: OO and game design questions
On Oct 20, 11:25 am, Jonathan Hartley tart...@tartley.com wrote: On Oct 18, 8:28 am, dex josipmisko...@gmail.com wrote: I'm building a turn based RPG game as a hobby. The design is becoming increasingly complicated and confusing, and I think I may have tendency to over-engineer simple things. Can anybody please check my problems-solutions and point me to more elegant solution? Every item/character/room is a separate object. Items/characters need to have references to room they are in, and room needs to have a list of references to items/characters that are contained within. I decided to use weak references. That way I can destroy object by deleting it, I don't have to destroy all references as well. In each object's __init__() that object is added to game_object list, and in each __del__() they are removed from game_object list. This mechanism keeps them safe from garbage collector. How pythonic is this design? In turn-based games, the order of action execution in battle can give unfair advantage to players. For example, if player's arm is crippled before his action is executed, he would do less damage. To offset this, I first execute all players' actions and calculate effects in first pass, then apply the effects in second pass. The effect can be health decrease by 15HP, item pick-up, 30p experience gain, etc. This means the player deals the same amount of damage no matter what happens to him in that turn. The difficult part is keeping track of various effects. I had to make separate class for various types of effects (ChangeAttributeEffect, GetItemEffect, LooseItemEffect). Each class stores weak reference to target object and has apply() method that applies the effect to object. I'm not satisfied with this as it's limiting, error-prone and uses metaprogramming. Is there a design pattern that would remember changes to an object, and apply them later? Sorry for the wall of text. One common way to store delayed actions is as a lambda (an anonymous function.) A lambda defines a new function: , and you can call this function later. The created function has no name, (but you can assign it to a variable to give it a name if you like) and can be called later: So in the game, you could have a collection 'effects', each one will be a lambda: effects = [] At the start of the round, as each entity makes its moves, they add lambdas to this collection. effects.append( lambda: decrease_hp(monster_a, 4) ) effects.append( lambda: lose_item(monster_a, item_b) ) Instead of appending it directly like this, I imagine the lambdas could be returned by the monster's 'act' or 'update' method: class Monster(): def act(self): # blah and finally return lambda: decrease_hp(monster_a, 4) Then for the start of a round, first you ask each monster what action it is going to perform: for monster in room.monsters: effects.append( monster.act() ) Then for the end of the round, call all the lambdas for effect in effects: effect() Also, I second other people's suggestions that you almost never need to be using __del__ nor weak references in Python, unless you are writing a project that is specifically related to complex resource allocation issues. In an rpg game like this, just store references to the objects that you need (which you have to do anyway, to use them), and forget about allocation issues. Don't be afraid to post follow-up questions, (or even to mail me off list.) I make hobbyist OpenGL games in Python myself, and although I'm no expert, I'd love to chat more about this for our mutual benefit. -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint -- should I just ignore it sometimes?
Seebs wrote: On 2010-10-19, Martin P. Hellwig martin.hell...@dcuktec.org wrote: Speaking without context here, so take it with as much salt as required ;-), it is not that unusual. However there are some things to consider, for example are all these attributes related to each other? If so wouldn't it be more pythonic to have one attribute which is a dictionary and store your stuff in there? I don't know. Does pythonic mean needlessly verbose? :) I did, in an early draft, have something that basically came down to: self.foo = {} self.foo['a'] = a() self.foo['b'] = b() and then I realized that I could just write: self.a = a() self.b = b() and spend a lot less extra typing on repeating something that, by virtue of being repeated constantly, was therefore meaningless. It wasn't creating a meaningful distinction, it wasn't showing a meaningful relationship... All these things are attributes of the thing itself, not attributes of its dictionary. Difficult to argue about meaning when you give a meaningless example :) The question you have to answer is : Is a and b attributes of self (whatever that is). Actually everything should be driven by its meaning, not if it's quicker to write or something like that. Regarding the first question about ignoring pylint: It's a tool, and requires a lot of configuration. 1/ define *your* coding rules (PEP 8 is just one coding rule among the others, it's only required if you want to commit into the standard library) 2/ When you know about your rules then configure pylint so it suits with those rules. 3/ Never ignore a defect reported by pylint. If a pylint rule does not satisfy you, disable it so pylint stops reporting it. except ValueError, e: Use meaningful names, this is so important. 'e' is not meaningful. 'exception' would be slighly better. On that particular case, pylint is right to complain. When dealing with such issue like I'm too lazy to write proper engligh always think that what is the most important thing is to save the Reader's time, not the Writer's time. Using 'e' would force to reader to introspect to code to get an idea of what 'e' is. Moreover, code completion makes use of long names costless. You should read this very good paper about naming: http://tottinge.blogsome.com/meaningfulnames/ JM -- http://mail.python.org/mailman/listinfo/python-list
Re: OO and game design questions
On Oct 20, 12:25 pm, Jonathan Hartley tart...@tartley.com wrote: On Oct 18, 8:28 am, dex josipmisko...@gmail.com wrote: I'm building a turn based RPG game as a hobby. The design is becoming increasingly complicated and confusing, and I think I may have tendency to over-engineer simple things. Can anybody please check my problems-solutions and point me to more elegant solution? Every item/character/room is a separate object. Items/characters need to have references to room they are in, and room needs to have a list of references to items/characters that are contained within. I decided to use weak references. That way I can destroy object by deleting it, I don't have to destroy all references as well. In each object's __init__() that object is added to game_object list, and in each __del__() they are removed from game_object list. This mechanism keeps them safe from garbage collector. How pythonic is this design? In turn-based games, the order of action execution in battle can give unfair advantage to players. For example, if player's arm is crippled before his action is executed, he would do less damage. To offset this, I first execute all players' actions and calculate effects in first pass, then apply the effects in second pass. The effect can be health decrease by 15HP, item pick-up, 30p experience gain, etc. This means the player deals the same amount of damage no matter what happens to him in that turn. The difficult part is keeping track of various effects. I had to make separate class for various types of effects (ChangeAttributeEffect, GetItemEffect, LooseItemEffect). Each class stores weak reference to target object and has apply() method that applies the effect to object. I'm not satisfied with this as it's limiting, error-prone and uses metaprogramming. Is there a design pattern that would remember changes to an object, and apply them later? Sorry for the wall of text. One common way to store delayed actions is as a lambda (an anonymous function.) A lambda defines a new function: , and you can call this function later. The created function has no name, (but you can assign it to a variable to give it a name if you like) and can be called later: So in the game, you could have a collection 'effects', each one will be a lambda: effects = [] At the start of the round, as each entity makes its moves, they add lambdas to this collection. effects.append( lambda: decrease_hp(monster_a, 4) ) effects.append( lambda: lose_item(monster_a, item_b) ) Instead of appending it directly like this, I imagine the lambdas could be returned by the monster's 'act' or 'update' method: class Monster(): def act(self): # blah and finally return lambda: decrease_hp(monster_a, 4) Then for the start of a round, first you ask each monster what action it is going to perform: for monster in room.monsters: effects.append( monster.act() ) Then for the end of the round, call all the lambdas for effect in effects: effect() Mr. Roy Smith already proposed using closures. I already did a similar thing in my code, but instead of decrease_hp() I have AttributeEffect class which is able to modify any attribute (in old RPGs some monsters could drain your intelligence, in my game laser gun hit will decrease HP as well as armor integrity). The first version looks like this (missing few checks): class AttributeEffect(object): '''Effect changes object's attribute by delta''' def __init__(self, obj, attrib, delta): self.obj = obj # reference to object the effect applies to self.attrib = attrib # name of attribute that effect applies to self.delta = delta # change of value for object.attribute def apply(self): value = getattr(self.obj, self.attrib) # todo: try, except value += self.delta setattr(self.obj(), self.attrib, value) Yesterday I learned that Python 3.0 introduces nonlocal keyword which would simplify defining effect functions and passing them along. Nice improvement. -- http://mail.python.org/mailman/listinfo/python-list
how to name a function in a comp lang (design)
A great piece about terminology in computer languages. * 〈The Poetry of Function Naming〉 (2010-10-18) By Stephen Wolfram. At: http://blog.stephenwolfram.com/2010/10/the-poetry-of-function-naming/ See also: • 〈The Importance of Terminology's Quality In Computer Languages〉 http://xahlee.org/UnixResource_dir/writ/naming_functions.html where i gave some examples of the naming. Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows: getting notification about power state changes
Hi Tim, Thanks a lot. I'll look into it. On 10/19/2010 11:30 AM, Tim Golden wrote: On 19/10/2010 10:06, Gelonida wrote: I'd like to be notified about certain events and call certain python functions depending on the event. call a function: - before (or after) the screen saver kicks in . . . - before (or after) the screen saver was stopped This should take you a certain amount of the way: http://timgolden.me.uk/python/win32_how_do_i/track-session-events.html I honestly don't know if the OS even knows when the monitor's switched on / when the disk is spun up. WMI has some power events: http://msdn.microsoft.com/en-us/library/aa394362%28v=VS.85%29.aspx http://timgolden.me.uk/python/wmi/cookbook.html#monitor-multiple-machines-for-power-events -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3: Is this a bug in urllib?
Johannes Bauer wrote: Hi, I've experienced the following behavior with Python3 of which I do not know if it's a bug or not. On two Python3.1 implementations, Python's urllib hangs when encountering a HTTP 301 (Redirect). The code to reproduce is a one-liner (actually, two-liner), Python from Ubuntu tree: Python 3.1.2 (r312:79147, Apr 15 2010, 15:35:48) [GCC 4.4.3] on linux2 Type help, copyright, credits or license for more information. from urllib import request; request.URLopener().open(http://google.de;) Also occurs on another Python version (Gentoo): Python 3.1.2 (release31-maint, Jun 9 2010, 23:58:21) [GCC 4.3.4] on linux2 The exchanged HTTP is: GET http://google.de HTTP/1.1 Accept-Encoding: identity Host: google.de User-Agent: Python-urllib/3.1 HTTP/1.1 301 Moved Permanently Via: 1.1 IMMPWISA01 Connection: Keep-Alive Proxy-Connection: Keep-Alive Content-Length: 218 Expires: Thu, 18 Nov 2010 15:18:40 GMT Date: Tue, 19 Oct 2010 15:18:40 GMT Location: http://www.google.de/ Content-Type: text/html; charset=UTF-8 Server: gws Cache-Control: public, max-age=2592000 X-XSS-Protection: 1; mode=block HTMLHEADmeta http-equiv=content-type content=text/html;charset=utf-8 TITLE301 Moved/TITLE/HEADBODY H1301 Moved/H1 The document has moved A HREF=http://www.google.de/;here/A. /BODY/HTML Although the content might indicate looping forever, it just hangs with no web traffic whatsoever (the TCP connection stays open, however). When interrupting with Ctrl-C, this is the calltrace: Traceback (most recent call last): File stdin, line 1, in module File /usr/lib/python3.1/urllib/request.py, line 1454, in open return getattr(self, name)(url) File /usr/lib/python3.1/urllib/request.py, line 1628, in open_http return self._open_generic_http(http.client.HTTPConnection, url, data) File /usr/lib/python3.1/urllib/request.py, line 1624, in _open_generic_http response.status, response.reason, response.msg, data) File /usr/lib/python3.1/urllib/request.py, line 1644, in http_error return self.http_error_default(url, fp, errcode, errmsg, headers) File /usr/lib/python3.1/urllib/request.py, line 1648, in http_error_default void = fp.read() File /usr/lib/python3.1/socket.py, line 214, in readinto return self._sock.recv_into(b) KeyboardInterrupt Can anyone tell me if this is a bug or expected behavior? While I'm not 100 percent sure it looks like a bug to me and I think you should report it at http://bugs.python.org Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: how to name a function in a comp lang (design)
Am 20.10.2010 13:14, schrieb Xah Lee: See also: • 〈The Importance of Terminology's Quality In Computer Languages〉 http://xahlee.org/UnixResource_dir/writ/naming_functions.html where i gave some examples of the naming. Xah ∑ http://xahlee.org/ ☄ I'd like to introduce a blog post by Stephen Wolfram, on the design process of Mathematica. In particular, he touches on the importance of naming of functions. The functions in Mathematica, are usually very well-named, in contrast to most other computing languages. Let me give a few example. [...] It is much easier to improve something good than to invent from scratch. When Lisp was born, Stephen Wolfram was still wearing diapers. For your information: Mathematica was my first Lisp-like language. I used it about 10 years almost every day and I love it because of the beauty of the concept. But Mathematica has two serious problems: first, there is only one implementation and it is commercial, and secondly, Mathematica is very, very slowly and does not generate executable code that can be used without Mathematica itself. Thus, comparisons to other languages, such as Lisp are not fair. regards Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: how to name a function in a comp lang (design)
On Oct 20, 4:52 am, Marc Mientki mien...@nonet.com wrote: Am 20.10.2010 13:14, schrieb Xah Lee: See also: • 〈The Importance of Terminology's Quality In Computer Languages〉 http://xahlee.org/UnixResource_dir/writ/naming_functions.html where i gave some examples of the naming. I'd like to introduce a blog post by Stephen Wolfram, on the design process of Mathematica. In particular, he touches on the importance of naming of functions. The functions in Mathematica, are usually very well-named, in contrast to most other computing languages. Let me give a few example. [...] thanks for your post. didn' t know you also use Mathematica. on the aspect of function naming, i think Mathematica is rather unique in its philosophy. Am not aware any other lang old or new follows a similar philosophy... possibly except javascript. It is much easier to improve something good than to invent from scratch. When Lisp was born, Stephen Wolfram was still wearing diapers. For your information: Mathematica was my first Lisp-like language. I used it about 10 years almost every day and I love it because of the beauty of the concept. But Mathematica has two serious problems: first, there is only one implementation and it is commercial, and secondly, Mathematica is very, very slowly and does not generate executable code that can be used without Mathematica itself. Thus, comparisons to other languages, such as Lisp are not fair. you are right... thought these aspects don't have much to do with function naming. i tend to think that Mathematica is that way due to a unique mind, Stephen Wolfram. And if i may say, i share much mindset with him with respect to many lang design issues. (or rather, Mathematica was my first lang for about 6 years too) But i think rather, Mathematica's lang design philosophy more has to do with certain pure mathematician mindset. This is somewhat similar to how haskell is a lang designed such that it is much independent of any concept of hardware. Same here with Mathematica, but on the naming aspect, Mathematica's function names is designed without even much relation to comp sci lingoes, but rather, the essense of ideas captured in a mathematical way. Xah ∑ http://xahlee.org/ ☄ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to name a function in a comp lang (design)
Am 20.10.2010 14:07, schrieb Xah Lee: On Oct 20, 4:52 am, Marc Mientkimien...@nonet.com wrote: Am 20.10.2010 13:14, schrieb Xah Lee: See also: • 〈The Importance of Terminology's Quality In Computer Languages〉 http://xahlee.org/UnixResource_dir/writ/naming_functions.html where i gave some examples of the naming. I'd like to introduce a blog post by Stephen Wolfram, on the design process of Mathematica. In particular, he touches on the importance of naming of functions. The functions in Mathematica, are usually very well-named, in contrast to most other computing languages. Let me give a few example. [...] thanks for your post. didn' t know you also use Mathematica. Not anymore, unfortunately. New job = no Mathematica. I tried with Maxima, but it is considered syntactically Middle Ages. Terribly confused (vectors, arrays, matrix, lists, sets - maxima does not know the motto of list for everything). It is much easier to improve something good than to invent from scratch. When Lisp was born, Stephen Wolfram was still wearing diapers. For your information: Mathematica was my first Lisp-like language. I used it about 10 years almost every day and I love it because of the beauty of the concept. But Mathematica has two serious problems: first, there is only one implementation and it is commercial, and secondly, Mathematica is very, very slowly and does not generate executable code that can be used without Mathematica itself. Thus, comparisons to other languages, such as Lisp are not fair. you are right... thought these aspects don't have much to do with function naming. Yes. I have it written because I see that you like to call Mathematica as a counter-example, in many cases. i tend to think that Mathematica is that way due to a unique mind, Stephen Wolfram. And if i may say, i share much mindset with him with respect to many lang design issues. Yes, me too, alone but for performance reasons, Mathematica in the area where I work (image processing) is not suitable. I mean - not research or rapid prototyping, but industrial image processing. (or rather, Mathematica was my first lang for about 6 years too) Mathematica = first language at all? No FORTRAN/BASIC/Pascal/C? regards Marc -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3: Is this a bug in urllib?
On Oct 20, 12:47 am, Johannes Bauer dfnsonfsdu...@gmx.de wrote: from urllib import request; request.URLopener().open(http://google.de;) aren't you supposed to call read on the return value of open? i.e., request.URLopener().open(http://google.de;).read() -- http://mail.python.org/mailman/listinfo/python-list
Re: Unicode questions
Tobiah wrote: I've been reading about the Unicode today. I'm only vaguely understanding what it is and how it works. Please correct my understanding where it is lacking. Unicode is really just a database of character information such as the name, unicode section, possible numeric value etc. These points of information are indexed by standard, never changing numeric indexes, so that 0x2CF might point to some character information set, that all the world can agree on. The actual image that gets displayed in response to the integer is generally assigned and agreed upon, but it is up to the software responding to the unicode value to define and generate the actual image that will represent that character. Correct. The actual images are called glyphs in Unicode-speak. Now for the mysterious encodings. There is the UTF-{8,16,32} which only seem to indicate what the binary representation of the unicode character points is going to be. Then there are 100 or so other encoding, many of which are language specific. ASCII encoding happens to be a 1-1 mapping up to 127, but then there are others for various languages etc. I was thinking maybe this special case and the others were lookup mappings, where a particular language user could work with characters perhaps in the range of 0-255 like we do for ASCII, but then when decoding, to share with others, the plain unicode representation would be shared? Why can't we just say unicode is unicode and just share files the way ASCII users do. Just have a huge ASCII style table that everyone sticks to. Please enlighten my vague and probably ill-formed conception of this whole thing. UTF-n are transfer encodings of the Unicode table (the one you are probably referring to). They represent the same code points, but using different trade-offs. If you're looking for a short intro to Unicode in Python, have a look at these talks I've given on the subject: http://www.egenix.com/library/presentations/#PythonAndUnicode http://www.egenix.com/library/presentations/#DesigningUnicodeAwareApplicationsInPython -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Oct 20 2010) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
exception during module initialization + python3
Has behavior of exception thrown during module initialization changed with python3? using boost::python, throwing a c++ exception in module initialization, I get: SystemError: initialization of ldpc_45 raised unreported exception I exepected to see the string associated with exception, which gave useful information (file not found, in this case). I believe under python2.6 this would have happened (but I could be mistaken) -- http://mail.python.org/mailman/listinfo/python-list
Re: overriding a property
On 19 Okt, 16:07, Benjamin Peterson benja...@python.org wrote: Lucasm lordlucraft at gmail.com writes: I would like to override the property for an instance of A to say the string 'bla'. A.return_five = blah I guess you did not test that. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: overriding a property
On 19 Okt, 18:28, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. class A(object): ... _five = 5 # class attribute shared by all instances ... @property ... def return_five(self): ... return self._five ... a = A() a._five = 'bla' # set an instance attribute b = A() print a.return_five bla print b.return_five 5 -- Steven Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? -- http://mail.python.org/mailman/listinfo/python-list
Re: annoying CL echo in interactive python / ipython
In mailman.29.1287515736.2218.python-l...@python.org Jed Smith j...@jedsmith.org writes: On Tue, Oct 19, 2010 at 2:35 PM, kj no.em...@please.post wrote: In mailman.24.1287510296.2218.python-l...@python.org Jed Smith j...@jed= smith.org writes: On Tue, Oct 19, 2010 at 1:37 PM, kj no.em...@please.post wrote: % stty -echo That doesn't do what you think it does. Gee, thanks. =A0That really helped. =A0I'll go talk to my guru now, and meditate over this. You're right, I could have been more clear. I was nudging you to go read the man page of stty(1), but since you won't and want to get snarky instead, I will for you: echo (-echo) Echo back (do not echo back) every character typed. I read that, and it did not add anything new to what I already knew about stty -echo. I'm going to guess that the percent sign in your prompt indicates that you're using zsh(1). With my minimally-customized zsh, the echo option is reset every time the prompt is displayed. That means you can type stty -echo, push CR, the echo option is cleared, then zsh immediately sets it before you get to type again. Wrong guess. After I run stty -echo, the echoing stays disabled: % stty -echo % date Wed Oct 20 10:01:46 EDT 2010 % date Wed Oct 20 10:01:47 EDT 2010 % date Wed Oct 20 10:01:48 EDT 2010 % date Wed Oct 20 10:01:49 EDT 2010 As to the guess about readline, I only observe this problem with python (interactive) and ipython, but not with, say, the Perl debugger, which uses readline as well. FWIW. ~kj -- http://mail.python.org/mailman/listinfo/python-list
Re: overriding a property
Lucasm wrote: On 19 Okt, 18:28, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. class A(object): ... _five = 5 # class attribute shared by all instances ... @property ... def return_five(self): ... return self._five ... a = A() a._five = 'bla' # set an instance attribute b = A() print a.return_five bla print b.return_five 5 -- Steven Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? You can dynamically change the instance's class: class A(object): ... @property ... def five(self): return 5 ... a = A() b = A() class B(type(b)): ... @property ... def five(self): return FIVE ... b.__class__ = B a.five 5 b.five 'FIVE' But still -- what you are trying looks like a bad idea. What's your usecase? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: overriding a property
On 20 Okt, 16:09, Peter Otten __pete...@web.de wrote: Lucasm wrote: On 19 Okt, 18:28, Steven D'Aprano st...@remove-this- cybersource.com.au wrote: On Tue, 19 Oct 2010 06:39:56 -0700, Lucasm wrote: Hi, A question. Is it possible to dynamically override a property? class A(object): @property def return_five(self): return 5 I would like to override the property for an instance of A to say the string 'bla'. class A(object): ... _five = 5 # class attribute shared by all instances ... @property ... def return_five(self): ... return self._five ... a = A() a._five = 'bla' # set an instance attribute b = A() print a.return_five bla print b.return_five 5 -- Steven Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? You can dynamically change the instance's class: class A(object): ... @property ... def five(self): return 5 ... a = A() b = A() class B(type(b)): ... @property ... def five(self): return FIVE ... b.__class__ = B a.five 5 b.five 'FIVE' But still -- what you are trying looks like a bad idea. What's your usecase? Peter Thanks for your answer. That's exactly the thing I'm doing right now and it works :) My use case is testing. I want to test a class and reduce the complexity of the output generated by certain properties. It would be nice to know alternatives to this approach. -- http://mail.python.org/mailman/listinfo/python-list
Re: overriding a property
On 10/20/2010 9:59 AM, Lucasm wrote: snip Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? Take a look at http://docs.python.org/reference/datamodel.html#descriptors The last paragraph of Section 3.4.2.3. Invoking Descriptors says: The property() function is implemented as a data descriptor. Accordingly, instances cannot override the behavior of a property. -John -- http://mail.python.org/mailman/listinfo/python-list
Re: Print to an IPP printer (pkipplib?)
On Fri, 15 Oct 2010 15:28:10 -0400, Adam Tauno Williams wrote: I've found the module pkipplib which seems to work well for things like interrogating an IPP (CUPS) server. But is there a way to send a print job to an IPP print queue? [and no, the local system knows nothing about the print architecture so popenlp is not an option]. I just want to send the data from a file handle to a remote IPP queue as a print job. See RFC 2910. -- martin@ | Martin Gregorie gregorie. | Essex, UK org | -- http://mail.python.org/mailman/listinfo/python-list
Tkinter (and IDLE) window docking? effect when dragging root window to edge of display
Python 2.6/2.7 (32-bit) for Windows: When I drag a Tkinter root window to the left, upper, or right edge of my display ... as soon as my mouse cursor hits the visible edge of the display ... as if I'm trying to dock the window on the edge in question ... a giant phantom Tkinter window pops up underneath my window showing the size and placement of my root window if I would release my mouse button. You can see the identical behavior if you drag a non-maxmized IDLE window to one of your screen edges (left, top, bottom). This behavior seems to be by design. I'm looking for a way to either disable this docking functionality or trap the docking event and size and position my root window according to custom needs. I've been googling this question and I can't seem to find the right terms to describe the event that is being raised or the behavior that I'm observing. Any ideas? Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: overriding a property
Lucasm lordlucr...@gmail.com writes: Thanks for the answers. I would like to override the property though without making special modifications in the main class beforehand. Is this possible? That will not be easy. When you access obj.return_five, python looks up 'return_five' in type(obj) to see what the return_five property even means. (See http://users.rcn.com/python/download/Descriptor.htm for details of how this works.) Since you can't change the source of A, you are left with two options: you can monkey-patch A.return_five to make it optionally consult the instance, or you can assign to instance's __class__ to make it point to a subclass of A that implements a different 'return_five'. Both options are fairly unpleasant, but I think I'd go with the first one. Others have spelled out the __class__-changing variant. While monkey-patching is not the cleanest of practices to adopt, in my mind it still beats assigning to __class__. Here is an example: # Wrap return_five so it supports per-instance customization, but # without copy-pasting the original. def wrap_return_five(orig): @property def wrapper(self): if 'return_five' in self.__dict__: return self.__dict__['return_five'] return orig.__get__(self, type(self)) return wrapper A.return_five = wrap_return_five(A.return_five) a = A() b = A() a.return_five 5 a.__dict__['return_five'] = 10 a.return_five 10 b.return_five 5 If you want, you can make a.return_five itself settable, but I'll leave that as an excercise for the reader. -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading Outlook .msg file using Python
On Oct 20, 1:41 am, Tim Golden m...@timgolden.me.uk wrote: On 19/10/2010 22:48, John Henry wrote: Looks like this flag is valid only if you are getting messages directly from Outlook. When reading the msg file, the flag is invalid. Same issue when accessing attachments. In addition, the MAPITable method does not seem to work at all when trying to get attachments out of the msg file (works when dealing with message in an Outlook mailbox). Eitherway, the display_name doesn't work when trying to display the filename of the attachment. I was able to get the date by using the PR_TRANSPORT_MESSAGE_HEADERS mapitags Ah, thanks. As you will have realised, my code is basically geared to reading an Outlook/Exchange message box. I hadn't really tried it on individual message files, except my original excerpt. If it were opportune, I'd be interested in seeing your working code. TJG When (and if) I finally figure out how to get it done, I surely will make the code available. It's pretty close. All I need is to figure out how to extract the attachments. Too bad I don't know (and don't have) C#. This guy did it so cleanly: http://www.codeproject.com/KB/office/reading_an_outlook_msg.aspx?msg=3639675#xx3639675xx May be somebody that knows both C# and Python can convert the code (not much code) and then the Python community will have it. As it stands, it seems the solution is available in Java, C#, VB but not Python. -- http://mail.python.org/mailman/listinfo/python-list
python shell silently ignores termios.tcsetattr()
This post is a continuation of an earlier thread called annoying CL echo in interactive python / ipython I found some more clues to the problem, although no solution yet. First, I found a post from 2009.05.09 that describes exactly the same situation I've observed (although it got no responses): http://groups.google.com/group/comp.emacs/browse_thread/thread/72973892717d0bfa I tried to fix the problem by applying the equivalent of stty -echo within a python interactive session, but discovered that this setting is immediately (and silently) overwritten. The following interaction illustrates what I mean. (I've added my comments, preceded by ###.) First I start the barest possible instance of Emacs (only the bare mininum of environment settings, and loading no configurations from an ~/.emacs file): % env -i HOME=$HOME DISPLAY=$DISPLAY TERM=$TERM /opt/local/bin/emacs -Q Within Emacs, the first command I execute is M-x shell, to bring up an Emacs shell. What follows is the interaction within this shell: sh-3.2$ stty -a ### first I get the initial settings for the terminal speed 9600 baud; 0 rows; 0 columns; lflags: icanon isig iexten -echo echoe -echok echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho -pendin -nokerninfo -extproc iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -iutf8 -ignbrk brkint -inpck -ignpar -parmrk oflags: opost -onlcr -oxtabs -onocr -onlret cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = undef; eol2 = undef; erase = undef; intr = ^C; kill = undef; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W; ### note the echo setting under lflags and the onlcr setting under ### oflags; also note that the stty -a command above was not echoed sh-3.2$ python ### next I start an interactive python session Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Type help, copyright, credits or license for more information. import termios import termios ### note the echoing old = termios.tcgetattr(1) old = termios.tcgetattr(1) new = termios.tcgetattr(1) new = termios.tcgetattr(1) new[3] = new[3] ~termios.ECHO ~termios.ONLCR new[3] = new[3] ~termios.ECHO old[3], new[3] old[3], new[3] (536872395, 536872385) (termios.tcsetattr(1, termios.TCSANOW, new), termios.tcgetattr(1)[3], old[3], new[3]) (termios.tcsetattr(1, termios.TCSANOW, new), termios.tcgetattr(1)[3], old[3], new[3]) (None, 536872385, 536872395, 536872385) ### The output above shows that the setting attempted through ### tcsetattr took momentarily... termios.tcgetattr(1) == old termios.tcgetattr(1) == old True ### ...but by this point it has already been reset back to its original value. termios.tcgetattr(1)[3], old[3], new[3] termios.tcgetattr(1)[3], old[3], new[3] (536872395, 536872395, 536872385) ^D sh-3.2$ stty -a ### after quitting python, the echo and onlcr settings have been reversed stty -a speed 9600 baud; 0 rows; 0 columns; lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl -echoprt -altwerase -noflsh -tostop -flusho -pendin -nokerninfo -extproc iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -iutf8 -ignbrk brkint -inpck -ignpar -parmrk oflags: opost onlcr -oxtabs -onocr -onlret cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow -dtrflow -mdmbuf cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = undef; eol2 = undef; erase = ^?; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W; sh-3.2$ Does anyone understand what's going on? Is there any way to prevent python from resetting the settings made with tcgetattr? (I realize that this is relatively low-level stuff, so it is unlikely that there's a clean solution; I'm hoping, however, that there may be a way to fool python into doing the right thing; after all, this strange behavior only happens under the Emacs shell; I don't observe it under, e.g., Terminal or xterm.) TIA! ~kj -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading Outlook .msg file using Python
On Oct 20, 9:01 am, John Henry john106he...@hotmail.com wrote: On Oct 20, 1:41 am, Tim Golden m...@timgolden.me.uk wrote: On 19/10/2010 22:48, John Henry wrote: Looks like this flag is valid only if you are getting messages directly from Outlook. When reading the msg file, the flag is invalid. Same issue when accessing attachments. In addition, the MAPITable method does not seem to work at all when trying to get attachments out of the msg file (works when dealing with message in an Outlook mailbox). Eitherway, the display_name doesn't work when trying to display the filename of the attachment. I was able to get the date by using the PR_TRANSPORT_MESSAGE_HEADERS mapitags Ah, thanks. As you will have realised, my code is basically geared to reading an Outlook/Exchange message box. I hadn't really tried it on individual message files, except my original excerpt. If it were opportune, I'd be interested in seeing your working code. TJG When (and if) I finally figure out how to get it done, I surely will make the code available. It's pretty close. All I need is to figure out how to extract the attachments. Too bad I don't know (and don't have) C#. This guy did it so cleanly: http://www.codeproject.com/KB/office/reading_an_outlook_msg.aspx?msg=... May be somebody that knows both C# and Python can convert the code (not much code) and then the Python community will have it. As it stands, it seems the solution is available in Java, C#, VB but not Python. BTW: For the benefit of future search on this topic, with the code listed above where: storage_flags = STGM_DIRECT | STGM_READ | STGM_SHARE_EXCLUSIVE I had to change it to: storage_flags = STGM_DIRECT | STGM_READ | STGM_SHARE_DENY_NONE | STGM_TRANSACTED otherwise I get a sharing violation (see http://efreedom.com/Question/1-1086814/Opening-OLE-Compound-Documents-Read-StgOpenStorage). For now, I am using a brute force method (http://mail.python.org/ pipermail/python-win32/2009-February/008825.html) to get the names of the attachments and if I need to extract the attachments, I pop up the message in Outlook and let Outlook extract the files. Ugly but fits my client's need for now. Hopefully there will be a cleaner solution down the road. Here's my code for brute forcing attachments out of the msg file (very ugly): def get_attachments(self, fileID): #from win32com.storagecon import * from win32com import storagecon import pythoncom flags = storagecon.STGM_READ | storagecon.STGM_SHARE_DENY_NONE | storagecon.STGM_TRANSACTED try: storage = pythoncom.StgOpenStorage (fileID, None, flags) except: return [] flags = storagecon.STGM_READ | storagecon.STGM_SHARE_EXCLUSIVE attachments=[] for data in storage.EnumElements (): print data[0], data[1] if data[1] == 2 or data[0] == __substg1.0_007D001F: stream = storage.OpenStream (data[0], None, flags) try: msg = stream.Read (data[2]) except: pass else: msg = repr (msg).replace(\ \x00,).strip(').replace(%23,#) if data[0] == __substg1.0_007D001F: try: attachments.append(msg.split(name=\)[1].split(\)[0]) except: pass return attachments -- http://mail.python.org/mailman/listinfo/python-list
Unix-head needs to Windows-ize his Python script
I have a handy Python script, which takes a few command-line arguments, and accepts a few options. I developed it on Unix, with very much of a Unix-mindset. Some Windows-using colleagues have asked me to make the script easy to use under Windows 7. I.e.: no command-line. Therefore, I want to adapt my script, with the minimum amount of work, so that it can have a double-clickable icon that brings up a small GUI to accept command-line options (including a couple of file-selectors for input and output files). I am Windows-illiterate, so I really would like to keep this as barebones as possible. Where should I look to learn more about how to do this? Thx! --G (P.S. in case it matters, it's OK to assume that Python will be installed on the Windows system; IOW, the script need not bring with it a Python interpreter and libraries.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter (and IDLE) window docking? effect when dragging root window to edge of display
On Wed, Oct 20, 2010 at 11:32 AM, pyt...@bdurham.com wrote: Python 2.6/2.7 (32-bit) for Windows: When I drag a Tkinter root window to the left, upper, or right edge of my display ... as soon as my mouse cursor hits the visible edge of the display ... as if I'm trying to dock the window on the edge in question ... a giant phantom Tkinter window pops up underneath my window showing the size and placement of my root window if I would release my mouse button. You can see the identical behavior if you drag a non-maxmized IDLE window to one of your screen edges (left, top, bottom). This behavior seems to be by design. I'm looking for a way to either disable this docking functionality or trap the docking event and size and position my root window according to custom needs. I've been googling this question and I can't seem to find the right terms to describe the event that is being raised or the behavior that I'm observing. It sounds like you are describing the Aero Snap feature in Windows 7. If you want to turn it off system wide, you can do that in the control panel: Open the Ease of Access control panel Click Make it easier to focus on tasks Check Prevent windows from being automatically arranged when moved to the edge of the screen I'm afraid I don't have any Tk experience to contribute, but this Stack Overflow thread may be slightly helpful, even though it's talking about trying to do this in .NET, and there aren't really any conclusions reached. http://stackoverflow.com/questions/2470685/disable-aero-snap-wpf At a guess the windows message triggering the resize would be a WM_SIZE. You may be able to override how your application responds to those messages to dock the way you want to. It'll probably take some experimentation, though. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix-head needs to Windows-ize his Python script
Write a small GUI in the easy-to-use and cross-platform wxPython module. All this GUI needs to do is allow them to input the arguments. The code can then import your stand-alone version of the script and execute its code, passing the arguments in. wxPython is just Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint -- should I just ignore it sometimes?
On 2010-10-20, Jean-Michel Pichavant jeanmic...@sequans.com wrote: except ValueError, e: Use meaningful names, this is so important. It's important, but meaning can come from idiom, not from the word used. 'e' is not meaningful. Sure it is. It's like i for a loop index. There's a reason mathematicians use x, not the_value_that_can_vary. When dealing with such issue like I'm too lazy to write proper engligh always think that what is the most important thing is to save the Reader's time, not the Writer's time. Using 'e' would force to reader to introspect to code to get an idea of what 'e' is. If the reader can't track a single-letter idiomatic name over two consecutive lines of code, I don't think I can save the reader time. The reader is beyond my ability to help at that point. Furthermore, long names take longer to read and process. As a *reader*, I vastly prefer: except foo, e: print Fatal error:, e to anything you could do with a longer name. Consider, admittedly a C example: for (int i = 0; i n; ++i) a[i] += 1; vs: for (int index_into_array = 0; index_into_array size_of_array; ++index_into_array) array_into_which_we_are_indexing[index_into_array] += 1; Here's the thing. The issue is not that I'm too lazy to write English. The issue is that English, like every other language, USES PRONOUNS. Because pronouns are a good way to MASSIVELY streamline communication. It's not just a convenience to the writer/speaker; it also makes life easier for the reader/listener. Short variable names are pronouns. They make sense when you'd use a pronoun in English. If we catch a KeyError, we print an error message including it. We'd use a pronoun. Makes sense to use a short variable name. Moreover, code completion makes use of long names costless. No, it doesn't. It preserves their higher cognitive load in parsing. Dogmatism about rejecting short variable names is inconsistent with the psychology of human readers. Compilers don't care about length of variable names. Humans do, and there are times when they benefit more from a short and recognizeable name than they do from a long and expressive one. -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix-head needs to Windows-ize his Python script
On 2010-10-20, Shawn Milochik sh...@milochik.com wrote: Write a small GUI in the easy-to-use and cross-platform wxPython module. All this GUI needs to do is allow them to input the arguments. The code can then import your stand-alone version of the script and execute its code, passing the arguments in. wxPython is just Python. No, it's not. You can't assume that any windows machine with Python installed also has wxPython installed. The only GUI kit that you can come close to assuming is Tkinter. -- Grant Edwards grant.b.edwardsYow! !! I am having fun!!! at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter (and IDLE) window docking? effect when dragging root window to edge of display
Jerry, It sounds like you are describing the Aero Snap feature in Windows 7. Bingo! You hit the nail and the head. Thank you very much! Regards, Malcolm -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix-head needs to Windows-ize his Python script
On Oct 20, 2010, at 2:00 PM, Grant Edwards wrote: On 2010-10-20, Shawn Milochik sh...@milochik.com wrote: ript and execute its code, passing the arguments in. wxPython is just Python. No, it's not. You can't assume that any windows machine with Python installed also has wxPython installed. The only GUI kit that you can come close to assuming is Tkinter. I didn't mean to imply that wxPython is in the standard library. Just that you write Python code when you create a wxPython app. I apologize for the lack of clarity. I recommended wxPython instead of Tkinter because of the opinions I've heard from other Python developers who prefer the former (I've never used Tkinter). Also, wxPython automatically looks native Mac, Windows, and Linux. Shawn -- http://mail.python.org/mailman/listinfo/python-list
Re: Classes in a class: how to access variables from one in another
On 18 Oct 2010 22:29:27 GMT Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Mon, 18 Oct 2010 09:34:07 -0700, Chris Rebert wrote: Also, Python's scoping rules, particularly for class-level scopes, don't work the way programmers from languages where nested classes are common would expect: [snip example] I'm sorry, I don't see that language Foo programmers will be surprised that Python is not language Foo is an argument against Python programmers using nested classes. Surely it's an argument against writing Foo in Python? Alright, alright, you made your point. You should go into politics. ;) /W -- To reach me via email, replace INVALID with the country code of my home country. But if you spam me, I'll be one sour Kraut. -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix-head needs to Windows-ize his Python script
On 2010-10-20, Shawn Milochik sh...@milochik.com wrote: On Oct 20, 2010, at 2:00 PM, Grant Edwards wrote: On 2010-10-20, Shawn Milochik sh...@milochik.com wrote: ript and execute its code, passing the arguments in. wxPython is just Python. No, it's not. You can't assume that any windows machine with Python installed also has wxPython installed. The only GUI kit that you can come close to assuming is Tkinter. I didn't mean to imply that wxPython is in the standard library. Just that you write Python code when you create a wxPython app. Ah, I see. While that is true, the same statement can be made for all of the GUI toolkits: PyQT, PyGTK, wxPython, pyFltk, etc. When creating a Python application using a GUI toolkit with a Python binding, all you have to do is write Python. I recommended wxPython instead of Tkinter because of the opinions I've heard from other Python developers who prefer the former (I've never used Tkinter). Also, wxPython automatically looks native Mac, Windows, and Linux. That's sort of true, but you've got to bundle the application correctly on Windows to make it happen (it didn't just work the last time I tried it). The OP didn't seem interested in bundling his app. I find Tkinter is much easier to use that wxPython for simple applications, but I generally switch to wxPython for anything more complex that a single top-level window with a handful of widgets in it. I also find the Tkinter API to be far more stable than wxWindows. I've one slightly complex Tkinter application that I wrote 10 years ago whose UI code is still running unchanged on brand new installs. The main advantage of Tkinter is that it's the standard GUI library for Python, and you can usually depend on it being installed on a Windows machine if Python is installed. It's included in both the standard Windows installer and the ActiveState windows installer. None of the other toolkits are. If, like the OP, you don't want to bundle up your application with a copy of Python and GUI libraries, Tkinter is pretty much your only option. -- Grant Edwards grant.b.edwardsYow! Am I accompanied by a at PARENT or GUARDIAN? gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Script to capture stderr of subprocess
On Tue, 19 Oct 2010 11:21:49 -0700, jslow...@gmail.com wrote: Actually, if it was possible, it would be nice to capture all the bytes going between stdin and stdout in a file as well for debugging purposes. If the child process expects to be running on a terminal, you would need to use a pseudo-terminal (pty). See the pty module (although the documentation assumes that you already understand how Unix ptys work). Redirecting stdin/stdout to pipes tends to interfere with interactive behaviour for a whole variety of reasons. Not least of which being that many programs specifically use something like isatty(fileno(stdin)) to determine whether they are being run interactively. cmd = ['/usr/local/bin/runcobol'] + sys.argv[1:] proc = subprocess.Popen(cmd, stderr=subprocess.PIPE) proc.communicate() if proc.returncode: f = file('/tmp/boom.txt', 'w') f.write( .join(cmd) + returned unexpectedly.\n) f.write(proc.stderr.read(-1)) f.close() sys.exit(proc.returncode) The .communicate() method waits for the process to terminate. Once that has happened, you can't call .read() on proc.stderr. The .communicate method returns a tuple, where the first item is whatever was written to stdout (provided that stdout was redirected to a pipe), and the second item is whatever was written to stderr (provided that stderr was redirected to a pipe). So you should use e.g.: errors = proc.communicate()[1] -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint -- should I just ignore it sometimes?
On Wed, 20 Oct 2010 12:47:02 +0200, Jean-Michel Pichavant wrote: except ValueError, e: Use meaningful names, this is so important. 'e' is not meaningful. 'exception' would be slighly better. While I agree with everything else you had to say, I have to take exception to this comment [pun intended]. e as a short name for a generic exception instance is perfectly reasonable, like: i, j, k for an index, or a loop variable e.g. for i in range(100) n for some other integer variable s for a string x for a float, or an arbitrary sequence object e.g. [x.spam() for x in some_sequence] and similar. The last example is very instructive. What do you gain by racking your brain for a more meaningful name instead of x? The obvious alternatives, obj or item, are equally generic as x, they don't add any further information. And how much information do you need? It's easy to parody: [some_sequence_item.spam() for some_sequence_item in some_sequence] The very shortness of the name is valuable because it reduces the *human* parsing time in reading, and there is no cost because the conventions are so familiar. The convention of for i in ... says this is a loop over an integer so strongly, that I would argue that for index in ... would actually *delay* comprehension. Furthermore, the use of a single letter cues the reader that this variable isn't notable -- there's nothing unusual or unconventional about it, or it isn't the important part of the algorithm, or that its scope is severely limited. For instance, consider the classic example of exchanging two variables in Python: a, b = b, a versus: thing, other_thing = other_thing, thing The first example puts the emphasis on the *technique*, not the variables. The second obscures it behind needlessly longer but still generic names. You are absolutely right to insist on meaningful variable names. Where you go wrong is to assume that single letter names can't be meaningful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
socket.sendto / UDP problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, When transmitting via UDP to a PLC, I run into a strange problem where socket.sendto returns double the number of characters sent in the datagram. I thought this was an error and used Wireshark to sniff the connection and discovered that it did, in fact, include two copies of the string I am transmitting in the same packet. The only thing differentiating this string from prior commands is its length. The functional ones are between 5 7 bytes (with 16 byte responses received successfully) but transmitting a 66-byte message actually results in 132 bytes being sent! I am running 2.6.6 on Windows XP, which I understand has a default minimum buffersize of 576 bytes which I would think is sufficient. Apologies if this is somewhat incoherent, I'm cross-eyed from staring at this! - - Todd - -- code -- def PLC_Functions(command, argument): Command is one of: GetTray, Status, SetText Argument is one of: tray number (as string), None, message (as string) The PC transmits and receives on socket 2260 (pcSocket) The PLC transmits and receives on socket 2002 The protocol used is UDP MegaMatPLC = (config.get('megamat','plcip'),int(config.get('megamat','targetport'))) # at some point it will be necessary to wrap these in TRY/EXCEPT to handle the socket errors # create UDP socket pcSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) # bind it pcSocket.bind((config.get('megamat','pcip'),int(config.get('megamat','sourceport' # make them blocking (i/o is 'fire-and-forget' to a PLC that may or may not respond in a given time.) # non-blocking fails and raises windows exceptions for some reason (20-Oct-2010) pcSocket.setblocking(True) if command == 'CallTray': # frame 1 (see docs for frame sequence) print 'Received call tray command for tray %s' %(argument) getReadyMsg = '0145\r' totalsent = 0 while totalsent len(getReadyMsg): sent = pcSocket.sendto(getReadyMsg[totalsent:],MegaMatPLC) if sent == 0: raise RunTimeError('Transmission failure. Please confirm MegaMat settings in megapy.ini') totalsent = totalsent + sent # Frame 2 response = '' while response.find('\r') 0: response = pcSocket.recv(17) if response == '': raise RunTimeError('PLC did not respond') #this should be changed. The MIF software will wait until it receives a response or timeout, not ABEND print response if response[0:4] == '0135': print 'Drive ready received.' #Frame 3 getReadyMsg2 = '016040\r' totalsent = 0 while totalsent len(getReadyMsg2): sent = pcSocket.sendto(getReadyMsg2[totalsent:],MegaMatPLC) if sent == 0: raise RunTimeError('Transmission failure. Please confirm MegaMat settings in megapy.ini') totalsent = totalsent + sent # Frame 4 response = '' while response.find('\r') 0: response = pcSocket.recv(16) if response == '': raise RunTimeError('PLC did not respond') #this should be changed. The MIF software will wait until it receives a response or timeout, not ABEND print response if response[0:4] == '0130': # Frame 5 # Transmit tray request if int(argument) 10: shelfPrefix = '' else: shelfPrefix = '000' shelf = shelfPrefix + argument unit = '001' stack = '01' There is a 10 digit number plus 40 blanks spaces after the shelf description built above. It is possible this is for storing shelf descriptions and barcodes on the PLC. We will follow the example of the MIF software and put a phony b/c and blank description. X is a field terminator and \r is the end of transmission (EoT.) fakeBarcode = '1234567890' fortySpacesField = ' '*40 + 'X\r' getShelfMsg = '0105' + shelf + unit + stack + fakeBarcode + fortySpacesField print 'Transmitting shelf request as follows: \n' + getShelfMsg print 'Get shelf length %i' % (len(getShelfMsg)) totalsent = 0 while totalsent len(getShelfMsg): sent = pcSocket.sendto(getShelfMsg[totalsent:],MegaMatPLC) print sent, totalsent, len(getShelfMsg) if sent == 0: raise
Re: Unix-head needs to Windows-ize his Python script
On 2010-10-20, Grant Edwards inva...@invalid.invalid wrote: On 2010-10-20, Shawn Milochik sh...@milochik.com wrote: Write a small GUI in the easy-to-use and cross-platform wxPython module. All this GUI needs to do is allow them to input the arguments. The code can then import your stand-alone version of the script and execute its code, passing the arguments in. wxPython is just Python. No, it's not. You can't assume that any windows machine with Python installed also has wxPython installed. The only GUI kit that you can come close to assuming is Tkinter. If using other toolkits, it's possible to compile a distributable package with dependencies using py2exe. That way even Python need not be installed. http://www.py2exe.org/ UTK -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix-head needs to Windows-ize his Python script
On 2010-10-20, Urpo T. Koira utko...@fuck.spam.gmail.com.invalid wrote: On 2010-10-20, Grant Edwards inva...@invalid.invalid wrote: On 2010-10-20, Shawn Milochik sh...@milochik.com wrote: Write a small GUI in the easy-to-use and cross-platform wxPython module. All this GUI needs to do is allow them to input the arguments. The code can then import your stand-alone version of the script and execute its code, passing the arguments in. wxPython is just Python. No, it's not. You can't assume that any windows machine with Python installed also has wxPython installed. The only GUI kit that you can come close to assuming is Tkinter. If using other toolkits, it's possible to compile a distributable package with dependencies using py2exe. That way even Python need not be installed. http://www.py2exe.org/ But, the OP said that he could assume that Python was already installed, that he was windows-illiterate, and that he wanted to keep things as bare-bones as possible. I've used wxWindows+py2exe in the past, and it can be made to work well. But, compared to distributing a simple source file for a Tkinter program, wxWindows+py2exe is _far_ from bare-bones, and not something to be casually undertaken by the windows-illiterate. -- Grant Edwards grant.b.edwardsYow! I'm pretending I'm at pulling in a TROUT! Am I gmail.comdoing it correctly?? -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint -- should I just ignore it sometimes?
Another situation in which I needed to disable such kind of warnings is while working with graphics modules. I often use variable names such as x, y, z for coordinates, or r,g,b for colors. Would longer names make the reader's life easier? Best regards, Matteo On Wed, Oct 20, 2010 at 9:37 PM, Steven D'Aprano st...@remove-this-cybersource.com.au wrote: On Wed, 20 Oct 2010 12:47:02 +0200, Jean-Michel Pichavant wrote: except ValueError, e: Use meaningful names, this is so important. 'e' is not meaningful. 'exception' would be slighly better. While I agree with everything else you had to say, I have to take exception to this comment [pun intended]. e as a short name for a generic exception instance is perfectly reasonable, like: i, j, k for an index, or a loop variable e.g. for i in range(100) n for some other integer variable s for a string x for a float, or an arbitrary sequence object e.g. [x.spam() for x in some_sequence] and similar. The last example is very instructive. What do you gain by racking your brain for a more meaningful name instead of x? The obvious alternatives, obj or item, are equally generic as x, they don't add any further information. And how much information do you need? It's easy to parody: [some_sequence_item.spam() for some_sequence_item in some_sequence] The very shortness of the name is valuable because it reduces the *human* parsing time in reading, and there is no cost because the conventions are so familiar. The convention of for i in ... says this is a loop over an integer so strongly, that I would argue that for index in ... would actually *delay* comprehension. Furthermore, the use of a single letter cues the reader that this variable isn't notable -- there's nothing unusual or unconventional about it, or it isn't the important part of the algorithm, or that its scope is severely limited. For instance, consider the classic example of exchanging two variables in Python: a, b = b, a versus: thing, other_thing = other_thing, thing The first example puts the emphasis on the *technique*, not the variables. The second obscures it behind needlessly longer but still generic names. You are absolutely right to insist on meaningful variable names. Where you go wrong is to assume that single letter names can't be meaningful. -- Steven -- http://mail.python.org/mailman/listinfo/python-list -- Matteo Landi http://www.matteolandi.net/ -- http://mail.python.org/mailman/listinfo/python-list
logging: StreamHandler’s newline terminator now co nfigurable
When StreamHandler writes a formatted log message to its stream, it adds a newline terminator. This behaviour is inherited by FileHandler and the other classes which derive from it (such as the rotating file handlers). For most people, that’s what they want, since they get log messages on separate lines without having to explicitly code newlines in their log messages. However, some people want the flexibility to not have this newline automatically appended to logged messages. Starting with Python 3.2, the message terminator will be configurable. This has been done by adding a terminator attribute to StreamHandler, which when emitting an event now writes the formatted message to its stream first, and then writes the terminator. If you don’t want newline termination for a handler, just set the handler instance’s terminator attribute to the empty string. There’s a small chance that this approach will cause unexpected behaviour – in the unlikely instance that someone is setting a terminator attribute on an a StreamHandler or one of its subclasses for their own, unrelated purposes. Other than that, the new behaviour should be backwards compatible. If this change is likely to adversely affect you for any reason, please let me know, by replying to this post. The change has already been checked into the py3k branch, and you are welcome to try it out. Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint -- should I just ignore it sometimes?
On 2010-10-20, Matteo Landi landima...@gmail.com wrote: Another situation in which I needed to disable such kind of warnings is while working with graphics modules. I often use variable names such as x, y, z for coordinates, or r,g,b for colors. Would longer names make the reader's life easier? Interesting point. Which is really easier to read: x, y, z = p.nextpoint() xCoordinate, yCoordinate, zCoordinate = polygon.nextPointCoordinates() -s -- Copyright 2010, all wrongs reversed. Peter Seebach / usenet-nos...@seebs.net http://www.seebs.net/log/ -- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) -- get educated! I am not speaking for my employer, although they do rent some of my opinions. -- http://mail.python.org/mailman/listinfo/python-list
Re: exception during module initialization + python3
Neal Becker wrote: Has behavior of exception thrown during module initialization changed with python3? using boost::python, throwing a c++ exception in module initialization, I get: SystemError: initialization of ldpc_45 raised unreported exception I exepected to see the string associated with exception, which gave useful information (file not found, in this case). I believe under python2.6 this would have happened (but I could be mistaken) I just tried it, and I'm not mistaken. On python2.6 I get my nice error message, but on python3.1.2 I just get the above SystemError: initialization of ldpc_45 raised unreported exception -- http://mail.python.org/mailman/listinfo/python-list
Re: merge list of tuples with list
Many thanks for all these suggestions! here is a short proof that you guys are absolutely right and my solution is pretty inefficient. One of your ways: $ python /[long_path]/timeit.py 'a=[(1,2,3),(4,5,6)];b=(7,8);[x+(y,) for x,y in zip(a,b)]' 100 loops, best of 3: 1.44 usec per loop And my way: $ python /[long_path]/timeit.py 'a=[(1,2,3), (4,5,6)];b=[7,8];map(tuple, map(lambda x: x + [b.pop(0)] , map(list, a)))' 10 loops, best of 3: 5.33 usec per loop I really appreciate your solutions but they bring me to a new question: Why is my solution so inefficient? The same operation without the list/tuple conversion $ python /[long_path]/timeit.py 'a=[[1,2,3], [4,5,6]];b=[7,8];map(lambda x: x + [b.pop(0)] , a)' 10 loops, best of 3: 3.36 usec per loop is still horrible slow. Could anybody explain me what it makes so slow? Is it the map() function or maybe the lambda construct? Greetings, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Data files with distutils and special paths
Hi! I was following the documentation about distutils [1] in order to install my application in a python-way. But installing it in /usr/local (following the official doc [2] too) with $ sudo python setup.py install --prefix=/usr/local The data files are created inside the python package, in /usr/local/lib/python2.6/dist-packages... The structure is very similar at the given in [1]: setup.py foo/__init.py__ foo(gui.py foo/core.py foo/data/gui/main.glade foo/data/images/logo.png And the setup.py: from setuptools import setup files = ['data/gui/*.glade', 'data/icons/*.png'] setup(name='foo', version='1.0', author='John Doe', author_email='john@example.com', packages=['foo'], dpackage_dir={'foo': 'foo'}, package_data={'foo': files}, ) What I'm missing? Regards, [1] http://docs.python.org/distutils/setupscript.html#installing-package-data [2] http://docs.python.org/install/#alternate-installation-unix-the-prefix-scheme -- Pablo Recio Quijano Desarrollador Django Yaco Sistemas - http://www.yaco.es/ -- http://mail.python.org/mailman/listinfo/python-list
Re: pylint -- should I just ignore it sometimes?
Seebs usenet-nos...@seebs.net writes: Interesting point. Which is really easier to read: x, y, z = p.nextpoint() xCoordinate, yCoordinate, zCoordinate = polygon.nextPointCoordinates() The latter uses camelCase, so it's horrible right out of the gate :-) -- \ “The cost of education is trivial compared to the cost of | `\ ignorance.” —Thomas Jefferson | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
python-imaging-sane
I'm trying to get my application to scan, create a .pdf, and then save it in a patient's folder. I found python-imaging-sane but I can't get things to work correctly. Here is what's happening at the command prompt: import sane sane.init() (16777235, 1, 0, 19) print sane.get_devices() [('canondr:libusb:001:002', 'Canon', 'P-150', 'sheetfed scanner')] s = sane.open(sane.get_devices()[0][0]) s.start() i = s.snap() Traceback (most recent call last): File input, line 1, in module File /usr/lib/python2.6/dist-packages/sane.py, line 243, in snap self.dev.snap( im.im.id, no_cancel ) _sane.error: Operation was cancelled Ultimately I would like to get it to scan duplex and do multipage docs. Thanks for any help. Mike Barron -- http://mail.python.org/mailman/listinfo/python-list
Re: Unix-head needs to Windows-ize his Python script
On Oct 20, 11:38 am, gb345 gb...@invalid.com wrote: I have a handy Python script, which takes a few command-line arguments, and accepts a few options. I developed it on Unix, with very much of a Unix-mindset. Some Windows-using colleagues have asked me to make the script easy to use under Windows 7. I.e.: no command-line. Therefore, I want to adapt my script, with the minimum amount of work, so that it can have a double-clickable icon that brings up a small GUI to accept command-line options (including a couple of file-selectors for input and output files). I am Windows-illiterate, so I really would like to keep this as barebones as possible. Where should I look to learn more about how to do this? Thx! --G (P.S. in case it matters, it's OK to assume that Python will be installed on the Windows system; IOW, the script need not bring with it a Python interpreter and libraries.) Teach them Windows key - Run - cmd or very useful Open Command Window Here right click option. http://www.downloadsquad.com/2009/02/09/windows-7-tip-elevated-command-prompt-anywhere/ Failing that you may try EasyDialogs http://www.doughellmann.com/PyMOTW/EasyDialogs/index.html The build in module is Mac only. The Windows version is available here. http://www.averdevelopment.com/python/EasyDialogs.html Waldemar -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.sendto / UDP problem
On 20/10/2010 21:20, Todd Walter wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hello, When transmitting via UDP to a PLC, I run into a strange problem where socket.sendto returns double the number of characters sent in the datagram. I thought this was an error and used Wireshark to sniff the connection and discovered that it did, in fact, include two copies of the string I am transmitting in the same packet. The only thing differentiating this string from prior commands is its length. The functional ones are between 5 7 bytes (with 16 byte responses received successfully) but transmitting a 66-byte message actually results in 132 bytes being sent! I am running 2.6.6 on Windows XP, which I understand has a default minimum buffersize of 576 bytes which I would think is sufficient. Apologies if this is somewhat incoherent, I'm cross-eyed from staring at this! [snip] The docs for 'sendto' say: The socket should not be connected to a remote socket, since the destination socket is specified by address. Could your problem be caused by you binding the socket to a source port, so it's going out both to the bound port _and_ the one given the binding? Have you tried using two sockets, one outgoing and the other incoming? BTW, your code for handling the response doesn't cope with it coming in a bit at a time. It loops discard any previous data from the previous iteration. Also, it's more Pythonic to say: while '\r' not in response: ... -- http://mail.python.org/mailman/listinfo/python-list
Re: merge list of tuples with list
On Wed, 20 Oct 2010 14:32:53 -0700, Daniel Wagner wrote: I really appreciate your solutions but they bring me to a new question: Why is my solution so inefficient? The same operation without the list/tuple conversion $ python /[long_path]/timeit.py 'a=[[1,2,3], [4,5,6]];b=[7,8];map(lambda x: x + [b.pop(0)] , a)' 10 loops, best of 3: 3.36 usec per loop is still horrible slow. What makes you say that? 3 microseconds to create four lists, two assignments, create a function object, then inside the map look up the global b twice, the method 'pop' twice, call the method twice, resize the list b twice, create an inner list twice, concatenate that list with another list twice, and stuff those two new lists into a new list... 3usec for all that in Python code doesn't seem unreasonable to me. On my PC, it's two orders of magnitude slower than a pass statement. That sounds about right to me. $ python -m timeit 1000 loops, best of 3: 0.0325 usec per loop $ python -m timeit 'a=[[1,2,3], [4,5,6]];b=[7,8];map(lambda x: x + [b.pop (0)] , a)' 10 loops, best of 3: 4.32 usec per loop Can we do better? $ python -m timeit -s 'a=[[1,2,3], [4,5,6]]; f = lambda x: x + [b.pop (0)]' 'b=[7,8]; map(f, a)' 10 loops, best of 3: 3.25 usec per loop On my system, moving the creation of the list a and the code being timed and into the setup code reduces the time by 25%. Not too shabby. Could anybody explain me what it makes so slow? Is it the map() function or maybe the lambda construct? lambdas are just functions -- there is no speed difference between a function def add(a, b): return a+b and lambda a, b: a+b The looping overhead of map(f, data) is minimal. But in this case, the function you're calling does a fair bit of work: lambda x: x + [b.pop(0)] This has to lookup the global b, resize it, create a new list, concatenate it with the list x (which creates a new list, not an in-place concatenation) and return that. The amount of work is non-trivial, and I don't think that 3us is unreasonable. But for large lists b, it will become slow, because resizing the list is slow. Popping from the start on a regular list has to move every element over, one by one. You may find using collections.deque will be *much* faster for large lists. (But probably not for small lists.) Personally, the approach I'd take is: a = [[1,2,3], [4,5,6]] b = [7,8] [x+[y] for x,y in zip(a,b)] Speedwise: $ python -m timeit -s 'a=[[1,2,3], [4,5,6]]; b=[7,8]' '[x+[y] for x,y in zip(a,b)]' 10 loops, best of 3: 2.43 usec per loop If anyone can do better than that (modulo hardware differences), I'd be surprised. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python3: Is this a bug in urllib?
On Oct 20, 8:32 pm, Justin Ezequiel justin.mailingli...@gmail.com wrote: On Oct 20, 12:47 am, Johannes Bauer dfnsonfsdu...@gmx.de wrote: from urllib import request; request.URLopener().open(http://google.de;) aren't you supposed to call read on the return value of open? i.e., .read() better yet, f = request.URLopener().open(http://google.de;) f.read() f.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: merge list of tuples with list
[b.pop(0)] This has to lookup the global b, resize it, create a new list, concatenate it with the list x (which creates a new list, not an in-place concatenation) and return that. The amount of work is non-trivial, and I don't think that 3us is unreasonable. I forgot to take account for the resizing of the list b. Now it makes sense. Thanks! Personally, the approach I'd take is: a = [[1,2,3], [4,5,6]] b = [7,8] [x+[y] for x,y in zip(a,b)] Speedwise: $ python -m timeit -s 'a=[[1,2,3], [4,5,6]]; b=[7,8]' '[x+[y] for x,y in zip(a,b)]' 10 loops, best of 3: 2.43 usec per loop If anyone can do better than that (modulo hardware differences), I'd be surprised. Yeah, this seems to be a nice solution. Greetings, Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: python shell silently ignores termios.tcsetattr()
In message i9n4ph$d7...@reader1.panix.com, kj wrote: I tried to fix the problem by applying the equivalent of stty -echo within a python interactive session, but discovered that this setting is immediately (and silently) overwritten. That seems reasonable behaviour; the command loop is resetting the terminal to a reasonable state to allow it to read the next command. But the command you execute can do anything it likes in-between. What’s wrong with that? -- http://mail.python.org/mailman/listinfo/python-list
Filename for stdout
If my python script is called with stdout (or stdin or stderr) redirected to a file, how can I find the filename under Linux? Under Windows? Thanks, RG -- http://mail.python.org/mailman/listinfo/python-list
Re: Filename for stdout
On Thu, Oct 21, 2010 at 6:17 AM, Richard Gibbs richard.gi...@smooth-stone.com wrote: If my python script is called with stdout (or stdin or stderr) redirected to a file, how can I find the filename under Linux? Under Windows? I don't believe there is a way to do this. The shell normally takes care of pipes. When you do: $ ./foo /tmp/foobar You're telling your shell to write the stdout output of foo to the file /tmp/foobar sys.stdout won't actually tell you anything useful. It's normally just a file descriptor. cheers James -- -- James Mills -- -- Problems are solved by method -- http://mail.python.org/mailman/listinfo/python-list
Re: Filename for stdout
On 2010-10-21, James Mills prolo...@shortcircuit.net.au wrote: On Thu, Oct 21, 2010 at 6:17 AM, Richard Gibbs richard.gi...@smooth-stone.com wrote: If my python script is called with stdout (or stdin or stderr) redirected to a file, how can I find the filename under Linux??? Under Windows? I don't believe there is a way to do this. There is, but it's not pretty. The shell normally takes care of pipes. And it takes care of redirects. Which, importantly for this case, are not the same thing. When you do: $ ./foo /tmp/foobar You're telling your shell to write the stdout output of foo to the file /tmp/foobar Not quite. You're telling the shell to attach the file /tmp/foobar to stdout before running the program foo. If the shell was reading data from foo's stdout and then writing it to /tmp/foobar, we'd be out of luck. But that's not what a redirect does. sys.stdout won't actually tell you anything useful. It's normally just a file descriptor. Ah, but file descriptors _can_ tell you something useful. :) The program below will print the filename(s) (if there are any) when stdout is a regular file. NB: to make it easy to test, it only searches below ., so you'd probably want to widen the search if you're doing this in a real program. [Asking sys.stdout for its fileno is a bit redundant since it's defined to be 1 in the Unix world.] [I've no clue how to do this under Windows.] [I also don't know what the answer is to the question the OP should have asked. But, I suspect this is a case of asking for a method to implement the wrong solution to an unstated problem.] In any case, here's how do do the wrong thing: #!/usr/bin/python import sys,os,stat write = sys.stderr.write # search for file(s) with given device/inode values def findFile(dev,ino): namelist = [] for root,dirs,files in os.walk(.): for name in files: path = os.path.join(root,name) statinfo = os.stat(path) fdev,fino = statinfo[stat.ST_DEV],statinfo[stat.ST_INO] if (dev,ino) == (fdev,fino): namelist.append(path) return namelist # get stat info of stdout, and if it's a regular file, search # filesystem under '.' for matching file(s) fd = sys.stdout.fileno() statinfo = os.fstat(fd) mode = statinfo[stat.ST_MODE] if stat.S_ISCHR(mode): write(stdout is a char device\n) elif stat.S_ISREG(mode): dev,ino = statinfo[stat.ST_DEV],statinfo[stat.ST_INO] write(stdout is a regular file on device %d inode %d\n % (dev,ino)) write(filename(s): %s\n % findFile(dev,ino)) elif stat.S_ISSOCK(mode): write(stdout is a socket\n) elif stat.S_ISFIFO(mode): write(stdout is a FIFO\n) else: write(stdout unknown type\n) -- http://mail.python.org/mailman/listinfo/python-list
how to scrutch a dict()
Not Hyp: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? Python does so often manage maps better than that... -- Phlip http://zeekland.zeroplayer.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: how to scrutch a dict()
Phlip phlip2...@gmail.com writes: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? Python does so often manage maps better than that... Untested: def _scrunch(**kwargs): return dict(k,v for k,v in kwargs.iteritems() if v is not None) Note: it's best not to use dict as a parameter name, since it is a built in function (dictionary constructor). It's also a bit of a code smell that you're using keyword args like that. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to scrutch a dict()
On Thu, Oct 21, 2010 at 2:32 PM, Phlip phlip2...@gmail.com wrote: Not Hyp: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? Python does so often manage maps better than that... Rather than creating a new dict why don't you just do: def _scrunch(d): for k, v in d.items(): if v is None: del d[k] cheers James -- -- James Mills -- -- Problems are solved by method -- http://mail.python.org/mailman/listinfo/python-list
Re: how to scrutch a dict()
On Wed, Oct 20, 2010 at 9:40 PM, Paul Rubin no.em...@nospam.invalid wrote: Phlip phlip2...@gmail.com writes: def _scrunch(**dict): result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? Python does so often manage maps better than that... Untested: def _scrunch(**kwargs): return dict(k,v for k,v in kwargs.iteritems() if v is not None) Also, in Python 3, one can instead use a dict comprehension (see PEP 274: http://www.python.org/dev/peps/pep-0274/ ), which makes this a bit more elegant: result = {k:v for k,v in kwargs.items() if v is not None} Cheers, Chris -- Smarmy code; now there's an interesting concept. http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: how to scrutch a dict()
Phlip phlip2...@gmail.com writes: Not Hyp: I don't know what this means; I hope it's not important. def _scrunch(**dict): You're clobbering the built-in ‘dict’ binding here. You're also requiring the input to be keyword parameters. Why not simply take a single parameter, and allow the *caller* to decide if they want to split up the key-value pairs? result = {} for key, value in dict.items(): if value is not None: result[key] = value return result That says throw away every item in a dict if the Value is None. Are there any tighter or smarmier ways to do that? I'm not sure “smarmy” means what you think it means; you might be amused to read a dictionary definition for that word. As for your code, it seems simple enough as is. You could translate it to a generator expression and feed that to the ‘dict’ constructor:: out_dict = dict( (key value) for (key, value) in in_dict.items() if value is not None) but that loses the utility of having it all wrapped up in a function, which would be my preference:: def scrunchdict(in_dict): out_dict = dict( (key value) for (key, value) in in_dict.items() if value is not None) return out_dict -- \“Some people, when confronted with a problem, think ‘I know, | `\ I'll use regular expressions’. Now they have two problems.” | _o__) —Jamie Zawinski, in alt.religion.emacs | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
[issue10092] calendar does not restore locale properly
Stephen Hansen me+pyt...@ixokai.io added the comment: I can't be entirely sure, because a) I have never even glanced at the calendar module, and b) my locale-fu is very weak, but my buildbot has consistently failed on this test since this commit: == ERROR: test_localecalendars (test.test_calendar.CalendarTestCase) -- Traceback (most recent call last): File /Users/pythonbuildbot/buildarea/3.x.hansen-osx-x86/build/Lib/test/test_calendar.py, line 264, in test_localecalendars locale=def_locale).formatmonthname(2010, 10, 10) File /Users/pythonbuildbot/buildarea/3.x.hansen-osx-x86/build/Lib/calendar.py, line 520, in formatmonthname with different_locale(self.locale): File /Users/pythonbuildbot/buildarea/3.x.hansen-osx-x86/build/Lib/calendar.py, line 490, in __enter__ _locale.setlocale(_locale.LC_TIME, self.locale) File /Users/pythonbuildbot/buildarea/3.x.hansen-osx-x86/build/Lib/locale.py, line 538, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting I will look into it in more detail tomorrow to try to provide more meaningful feedback, but I think this fix has introduced a problem. If someone sees what before I have time to dig into this unfamiliar territory, yay. :) -- nosy: +ixokai ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10092 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10150] Local references not released after exception
Georg Brandl ge...@python.org added the comment: Alex is correct. (You can prove that by raising and catching another exception before the second getrefcount().) -- nosy: +georg.brandl resolution: - wont fix status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10150 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10092] calendar does not restore locale properly
Georg Brandl ge...@python.org added the comment: Let's see if r85735 fixed this. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10092 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10092] calendar does not restore locale properly
Changes by Georg Brandl ge...@python.org: Removed file: http://bugs.python.org/file19286/unnamed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10092 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10151] Docs: can globals() be updated?
New submission from Thomas Guettler guet...@thomas-guettler.de: Hi, the documentation of globals() is missing a note if you can update the dictionary: http://docs.python.org/library/functions.html?highlight=globals#globals For locals() it is documented: http://docs.python.org/library/functions.html?highlight=locals#locals -- assignee: d...@python components: Documentation messages: 119192 nosy: d...@python, guettli priority: normal severity: normal status: open title: Docs: can globals() be updated? versions: Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10151 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10128] multiprocessing.Pool throws exception with __main__.py
Changes by Ask Solem a...@opera.com: -- resolution: - invalid status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10128 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue8863] Display Python backtrace on SIGSEGV, SIGFPE and fatal error
Antoine Pitrou pit...@free.fr added the comment: I don't think that a command line option and an environment variable is pratical for an OS distributor. Environment variables are probably the most practical for OS vendors, since they can simply set them in /etc/profile.d (Mandriva does that with PYTHONDONTWRITEBYTECODE :-/). If it's an env variable, though, it should be clear that it's CPython-specific, so I'm not sure how to call it. CPYTHONNOSEGFAULTHANDLER? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue8863 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10092] calendar does not restore locale properly
Boštjan Mejak bostjan.me...@gmail.com added the comment: import calendar calendar.LocaleTextCalendar(locale='fr_FR').formatmonthname(2010,10,10) Traceback (most recent call last): File stdin, line 1, in module File C:\Python27\lib\calendar.py, line 522, in formatmonthname with TimeEncoding(self.locale) as encoding: File C:\Python27\lib\calendar.py, line 489, in __enter__ self.oldlocale = _locale.setlocale(_locale.LC_TIME, self.locale) File C:\Python27\lib\locale.py, line 531, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting Is it just my machine or is this a common thing on most machines? If I do a test and I try to set a locale with the setlocale() method, I get this locale.Error: unsupported locale setting. So I gather that the method setlocale() is broken and we should fix it before fixing the Locale{Text,HTML}Calendar ones. The way setlocale() is implemented, is this: def setlocale(category, value=None): setlocale(integer,string=None) - string. Activates/queries locale processing. if value not in (None, '', 'C'): raise Error, '_locale emulation only supports C locale' return 'C' Please note that the online documentation documents its API like this: locale.setlocale(category[, locale]) See http://docs.python.org/library/locale.html#locale.setlocale So you can see that the implementation differs from the documentation in that it documents the 2nd argument as 'locale' where in the implementation there is 'value'. If that's a bug, I don't know. Anyway, please fix the implementation. I found out some very interesting thing... Note the line if value not in (None, '', 'C') in the implementation. This is the faulty thing in the function because NoneType is not iterable. Test it for yourself in the interpreter: value = None value not in None Traceback (most recent call last): File stdin, line 1, in module TypeError: argument of type 'NoneType' is not iterable So this setlocale() always raises an error. Please fix this. Of course, this is valid: value = None value is not None False No error here. So try to combine this into a workable patch. Thanks. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10092 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10092] calendar does not restore locale properly
Georg Brandl ge...@python.org added the comment: Bostjan, both your points are invalid. First, the locale settings that a machine supports vary greatly. fr_FR doesn't need to be a valid setting on your machine. Second, val in None will always fail. val in (None, ...) will succeed, since you're testing membership in the given tuple that includes None. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10092 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10151] Docs: can globals() be updated?
Georg Brandl ge...@python.org added the comment: It is documented, however, that globals() returns the dictionary of a module, which can be modified. For locals(), the situation is quite more complicated, which is why the warning there is warranted. -- nosy: +georg.brandl resolution: - works for me status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10151 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10092] calendar does not restore locale properly
Tim Golden m...@timgolden.me.uk added the comment: Boštjan, the code segment you quote is the *fallback* if the C module hasn't been built for some reason. The module simply calls through to the underlying C Library. I notice you're running on Windows, so this is a useful MS page: http://msdn.microsoft.com/en-us/library/x99tb11d%28VS.71%29.aspx and you can see there that a call of setlocale (LC_ALL, English) is valid (of French if you prefer): Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. import locale locale.setlocale (locale.LC_ALL, French) 'French_France.1252' -- nosy: +tim.golden ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10092 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10152] symtable.c: ste_tmpname uninitialized
New submission from Stefan Krah stefan-use...@bytereef.org: Found by Valgrind: ==3947== Use of uninitialised value of size 8 ==3947==at 0x5716D13: _itoa_word (in /lib/libc-2.8.90.so) ==3947==by 0x5719F53: vfprintf (in /lib/libc-2.8.90.so) ==3947==by 0x5743239: vsnprintf (in /lib/libc-2.8.90.so) ==3947==by 0x4956AF: PyOS_vsnprintf (mysnprintf.c:74) ==3947==by 0x495661: PyOS_snprintf (mysnprintf.c:47) ==3947==by 0x49FC1E: symtable_new_tmpname (symtable.c:1092) ==3947==by 0x4A2CE6: symtable_handle_comprehension (symtable.c:1648) ==3947==by 0x4A2F7C: symtable_visit_listcomp (symtable.c:1673) ==3947==by 0x4A1C63: symtable_visit_expr (symtable.c:1363) ==3947==by 0x4A07C5: symtable_visit_stmt (symtable.c:1178) ==3947==by 0x4A0BBE: symtable_visit_stmt (symtable.c:1200) ==3947==by 0x4A08D4: symtable_visit_stmt (symtable.c:1187) The patch fixes the issue (unless the intent was to use somewhat randomized tmpnames). -- files: ste_tmpname.patch keywords: patch messages: 119198 nosy: skrah priority: normal severity: normal status: open title: symtable.c: ste_tmpname uninitialized Added file: http://bugs.python.org/file19293/ste_tmpname.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10152 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10152] symtable.c: ste_tmpname uninitialized
Changes by Stefan Krah stefan-use...@bytereef.org: -- stage: - patch review type: - behavior versions: +Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10152 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6864] IDLE 2.6.1 locks up on Mac OS 10.6
Ronald Oussoren ronaldousso...@mac.com added the comment: Richard: I don't understand your message. What abort are you talking about? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6864 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue1349106] email.Generator does not separate headers with \r\n
Malcolm Box malcolm@gmail.com added the comment: David: Great to see a patch for this. You're right of course, 8bit isn't binary - I meant binary. The main place this shows up is when you're using MIME not in email (e.g. on the web), where binary transport is entirely possible. This fix should mean that the MIME libraries are much more usable in non-email environments. Thanks. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue1349106 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10153] Memory leak in pythonrun.c
New submission from Stefan Krah stefan-use...@bytereef.org: Found by Valgrind, patch attached: ==4921== 24 bytes in 1 blocks are definitely lost in loss record 419 of 2,694 ==4921==at 0x4C2412C: malloc (vg_replace_malloc.c:195) ==4921==by 0x417F06: _PyObject_New (object.c:244) ==4921==by 0x520C4E: PyFile_NewStdPrinter (fileobject.c:364) ==4921==by 0x499438: Py_InitializeEx (pythonrun.c:281) ==4921==by 0x49951E: Py_Initialize (pythonrun.c:322) ==4921==by 0x4B2579: Py_Main (main.c:587) ==4921==by 0x417D6B: main (python.c:51) -- components: Interpreter Core files: pythonrun.patch keywords: patch messages: 119201 nosy: skrah priority: normal severity: normal stage: patch review status: open title: Memory leak in pythonrun.c type: behavior versions: Python 3.2 Added file: http://bugs.python.org/file19294/pythonrun.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10153 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10152] symtable.c: ste_tmpname uninitialized
Changes by Stefan Krah stefan-use...@bytereef.org: -- components: +Interpreter Core ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10152 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10149] Data truncation in expat parser
R. David Murray rdmur...@bitdance.com added the comment: For other reviewers, I'm reposting just his python program as a text file. Maciek: I myself don't know enough about expat to comment, but is it possible you have an issue similar to issue 10026? -- nosy: +r.david.murray Added file: http://bugs.python.org/file19295/xml-parse-revisions.py ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10149 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10152] symtable.c: ste_tmpname uninitialized
Changes by Benjamin Peterson benja...@python.org: -- assignee: - benjamin.peterson nosy: +benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10152 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7473] Compile error when building a 3-way universal framework when a 2-way universal framework is present
Ronald Oussoren ronaldousso...@mac.com added the comment: I've verified that the patch does not cause problems when building the OSX installer. That patch should be applied, with a short comment that explains why the code block is disabled for framework builds. -- versions: -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7473 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10128] multiprocessing.Pool throws exception with __main__.py
Michael Olson ol...@irinim.net added the comment: Ummm, I think I've been unclear on where I was making changes, I changed lib\multiprocessing\forking.py to fix the issue. Patch attached. -- keywords: +patch resolution: invalid - status: closed - open Added file: http://bugs.python.org/file19296/issue10128.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10128 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10128] multiprocessing.Pool throws exception with __main__.py
Michael Olson ol...@irinim.net added the comment: As a note, I didn't attach a patch at first because I was fairly sure I was kludging it into submission, but at least this makes it clear as to what I did. v/r -- Michael Olson -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10128 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7473] Compile error when building a 3-way universal framework when a 2-way universal framework is present
Ronald Oussoren ronaldousso...@mac.com added the comment: Committed the fix for 3.2 in r85744, for 2.7 in r85745 and for 3.1 in r85746 BTW. The installer does mention which architectures are supported, both in a README on the disk image and in one of the readme screens in the installer. -- stage: needs patch - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7473 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue763708] Failures in test_macostools for --enable-unicode=ucs4
Changes by Ronald Oussoren ronaldousso...@mac.com: Removed file: http://bugs.python.org/file13487/issue763708.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue763708 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue763708] Failures in test_macostools for --enable-unicode=ucs4
Ronald Oussoren ronaldousso...@mac.com added the comment: I've attached a new patch that works for me. The new patch doesn't try to warn when running the configure script, but bails out when you run make by using an '#error' in pymacconfig.h. (Removing 2.6 because that's in security-fix-only mode and 3.1 because this issue only affects 2.x) -- keywords: -26backport, needs review, patch versions: -Python 2.6, Python 3.1 Added file: http://bugs.python.org/file19297/issue763708.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue763708 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3367] Uninitialized value read in parsetok.c
Stefan Krah stefan-use...@bytereef.org added the comment: I can still reproduce it in py3k just by hitting Ctrl-D in the interactive interpreter: $ valgrind --db-attach=yes --suppressions=Misc/valgrind-python.supp ./python ==16724== Memcheck, a memory error detector ==16724== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==16724== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info ==16724== Command: ./python ==16724== Python 3.2a3+ (py3k:85735M, Oct 20 2010, 14:19:24) [GCC 4.2.4 (Ubuntu 4.2.4-3ubuntu4)] on linux2 Type help, copyright, credits or license for more information. ==16724== Conditional jump or move depends on uninitialised value(s) ==16724==at 0x4F4DB7: parsetok (parsetok.c:198) ==16724==by 0x4F4B03: PyParser_ParseFileFlagsEx (parsetok.c:100) ==16724==by 0x49C8FB: PyParser_ASTFromFile (pythonrun.c:1884) ==16724==by 0x49AAC6: PyRun_InteractiveOneFlags (pythonrun.c:1124) ==16724==by 0x49A7B8: PyRun_InteractiveLoopFlags (pythonrun.c:1035) ==16724==by 0x49A677: PyRun_AnyFileExFlags (pythonrun.c:1004) ==16724==by 0x4B1EDE: run_file (main.c:296) ==16724==by 0x4B293E: Py_Main (main.c:681) ==16724==by 0x417D6B: main (python.c:51) ==16724== ==16724== ==16724== Attach to debugger ? --- [Return/N/n/Y/y/C/c] y ==16724== starting debugger with cmd: /usr/bin/gdb -nw /proc/16725/fd/1014 16725 GNU gdb 6.8-debian Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type show copying and show warranty for details. This GDB was configured as x86_64-linux-gnu... Attaching to program: /proc/16725/fd/1014, process 16725 0x004f4db7 in parsetok (tok=0x6c705d0, g=0x80bac0, start=256, err_ret=0x7fefffee0, flags=0x7fe1c) at Parser/parsetok.c:198 198 if (a = tok-line_start) (gdb) -- nosy: +skrah resolution: fixed - status: closed - open versions: +Python 3.2 -Python 2.6, Python 3.0 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue3367 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6864] IDLE 2.6.1 locks up on Mac OS 10.6
Richard pub...@careaga.net added the comment: Sorry to be obscure, Ronald. I mistook my configuration problem, described below for the original problem. But I can reproduce the problem with opening an existing file under IDLE, which is a segmentation fault. When opening a new window, I get a blank screen but no prompt. I should have done this before on my two boxes. It shows pretty clearly that the abort trap problem in 2.6.x is my configuration problem. On the development box, I have mutliple Pythons, with varying degrees of IDLE success; on the production box I have only the factory installed 2.6.1 with no IDLE problem other than the one originally reported. Both boxes are under 10.6.4. Development: Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin $ /usr/bin/idle2.6 CGColor with 1 components Abort trap # This is probably due to paths crossed with 2.6.6 $ sudo /usr/bin/idle2.6 2010-10-20 10:12:16.329 Python[11954:1707] __CFServiceControllerBeginPBSLoadForLocalizations timed out while talking to pbs 2010-10-20 10:12:31.868 Python[11954:1707] __CFServiceControllerBeginPBSLoadForLocalizations timed out while talking to pbs 0 #IDLE works, otherwise, except for the segmentation issue Production: Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin #IDLE works, except for the segmentation issue for completeness: Development: Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin $ idle3 Floating point exception Development: Python 2.7 (r27:82508, Jul 3 2010, 21:12:11) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** Development: Python 2.6.6 (r266:84292, Aug 28 2010, 10:17:47) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin #IDLE hangs -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6864 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9670] Exceed Recursion Limit in Thread
Ronald Oussoren ronaldousso...@mac.com added the comment: The attached patch explicitly sets the minimal stack size to about 704K, which is the minimal size where 'def f(): f()' doesn't cause a buserror when run in a thread. -- keywords: +needs review, patch stage: needs patch - patch review Added file: http://bugs.python.org/file19298/issue9670.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9670 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6763] Crash on mac os x leopard in mimetypes.guess_type (or PyObject_Malloc)
Ronald Oussoren ronaldousso...@mac.com added the comment: I'm closing this as a duplicate of #9670, that is: too deep recursion in a thread doesn't trigger the appropriate exception but causes a hard crash instead. I have attached a patch to that issue (but haven't applied it yet, I'd like someone else too look at the patch as well). BTW. I don't think this issue is serious enough to warrant a backport to 2.6. -- resolution: - duplicate status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6763 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue9047] Python 2.7rc2 includes -isysroot twice on each gcc command line
Ronald Oussoren ronaldousso...@mac.com added the comment: Marc-Andre: does the current HEAD of the 2.7 and 3.2 branches work for you? The build still has duplicate flags, but that doesn't seem to cause problems on my machines. If it also doesn't cause problems on your machines I'd prefer to close this issue as won't fixed because cleaning up the duplicate flags is non-trivial. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue9047 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10154] locale.normalize strips - from UTF-8, which fails on Mac
New submission from Stephen Hansen me+pyt...@ixokai.io: In the course of investigating issue10092, Georg discovered that the behavior of locale.normalize() on Mac is bad. Basically, en_US.UTF-8 is how the correct locale string should be spelled on the Mac. If you drop the dash, it fails: which locale.normalize does, so you can't pass the return value of the function to setlocale, even though that's what its documented to be for. If that isn't clear, this should demonstrate (from /branches/py3k): Top-2:build pythonbuildbot$ ./python.exe Python 3.2a3+ (py3k:85631, Oct 17 2010, 06:45:22) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type help, copyright, credits or license for more information. import locale [51767 refs] locale.normalize(en_US.UTF-8) 'en_US.UTF8' [51770 refs] locale.setlocale(locale.LC_TIME, 'en_US.UTF8') Traceback (most recent call last): File stdin, line 1, in module File /Users/pythonbuildbot/test/build/Lib/locale.py, line 538, in setlocale return _setlocale(category, locale) locale.Error: unsupported locale setting [51816 refs] locale.setlocale(locale.LC_TIME, 'en_US.UTF-8') 'en_US.UTF-8' [51816 refs] The precise same behavior exists on my stock/system Python 2.6, too, fwiw. (Not that it can be fixed on 2.6, but maybe 2.7?) -- assignee: ronaldoussoren components: Library (Lib), Macintosh messages: 119213 nosy: ixokai, ronaldoussoren priority: normal severity: normal status: open title: locale.normalize strips - from UTF-8, which fails on Mac type: behavior versions: Python 2.7, Python 3.1, Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10154 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com