Re: Dynamic variable creation from string

2011-12-10 Thread Nobody
On Fri, 09 Dec 2011 01:55:28 -0800, Massi wrote: > Thank you all for your replies, first of all my Sum function was an > example simplifying what I have to do in my real funciton. In general > the D dictionary is complex, with a lot of keys, so I was searching > for a quick method to access all th

Re: order independent hash?

2011-12-10 Thread Lie Ryan
On 12/11/2011 11:17 AM, Chris Angelico wrote: On Sun, Dec 11, 2011 at 10:58 AM, Lie Ryan wrote: On 12/09/2011 10:27 PM, Steven D'Aprano wrote: Except for people who needed dicts with tens of millions of items. who should be using a proper DBMS in any case. Not necessarily. "Database" usual

Re: Overriding a global

2011-12-10 Thread Terry Reedy
On 12/10/2011 7:14 PM, Terry Reedy wrote: On 12/10/2011 3:47 PM, Roy Smith wrote: What I really want to do is: def function(self): Add a global statement to rebind a global name: global logger But I see that that is not what you want to do, which is to override the global name just within

Re: order independent hash?

2011-12-10 Thread Chris Angelico
On Sun, Dec 11, 2011 at 10:58 AM, Lie Ryan wrote: > On 12/09/2011 10:27 PM, Steven D'Aprano wrote: >> Except for people who needed dicts with tens of millions of items. > > who should be using a proper DBMS in any case. Not necessarily. "Database" usually implies disk-based and relational, featur

Re: Overriding a global

2011-12-10 Thread Terry Reedy
On 12/10/2011 3:47 PM, Roy Smith wrote: What I really want to do is: def function(self): Add a global statement to rebind a global name: global logger logger = logger.getChild('function') logger.debug('stuff') logger.debug('other stuff') which lets me not ha

Re: order independent hash?

2011-12-10 Thread Lie Ryan
On 12/09/2011 10:27 PM, Steven D'Aprano wrote: On Thu, 08 Dec 2011 10:30:01 +0100, Hrvoje Niksic wrote: In a language like Python, the difference between O(1) and O(log n) is not the primary reason why programmers use dict; they use it because it's built-in, efficient compared to alternatives,

Re: Multiprocessing bug, is information ever omitted from a traceback?

2011-12-10 Thread Terry Reedy
On 12/10/2011 2:02 PM, Chris Angelico wrote: There's a few differences between 2.6 and 2.7; not usually enough to be concerned about in daily use, but when dealing with weird issues, it helps to have the latest release. There are 2 issues. First, 2.7.2 has perhaps a couple hundred bug fixes s

Re: Misleading error message of the day

2011-12-10 Thread Lie Ryan
On 12/09/2011 03:57 PM, alex23 wrote: On Dec 9, 11:46 am, Lie Ryan wrote: perhaps the one that talks about `a, a.foo = 1, 2` blowing up? Are you sure you're not confusing this with the recent thread on 'x = x.thing = 1'? Ah, yes I do -- http://mail.python.org/mailman/listinfo/python-list

Re: Overriding a global

2011-12-10 Thread Roy Smith
MRAB wrote: > or use 'globals': > > def function(self): > logger = globals()['logger'].getChild('function') > logger.debug('stuff') > logger.debug('other stuff') Ah-ha! That's precisely what I was looking for. Much appreciated. -- http://mail.python.org/mailma

Re: Overriding a global

2011-12-10 Thread MRAB
On 10/12/2011 20:47, Roy Smith wrote: I've got a code pattern I use a lot. In each module, I create a logger for the entire module and log to it all over: logger = logging.getLogger('my.module.name') class Foo: def function(self): logger.debug('stuff') logger.debug('other stu

Overriding a global

2011-12-10 Thread Roy Smith
I've got a code pattern I use a lot. In each module, I create a logger for the entire module and log to it all over: logger = logging.getLogger('my.module.name') class Foo: def function(self): logger.debug('stuff') logger.debug('other stuff') and so on. This works, but every on

Re: WeakValueDict and threadsafety

2011-12-10 Thread Darren Dale
On Dec 10, 2:09 pm, Duncan Booth wrote: > Darren Dale wrote: > > On Dec 10, 11:19 am, Duncan Booth > > wrote: > >> Darren Dale wrote: > > def get_data(oid): > >     with reglock: > >         data = registry.get(oid, None) > >         if data is None: > >             data = make_data(oid) > >  

Re: WeakValueDict and threadsafety

2011-12-10 Thread Duncan Booth
Darren Dale wrote: > On Dec 10, 11:19 am, Duncan Booth > wrote: >> Darren Dale wrote: > def get_data(oid): > with reglock: > data = registry.get(oid, None) > if data is None: > data = make_data(oid) > registry[oid] = data > return data > > Does t

Re: Multiprocessing bug, is information ever omitted from a traceback?

2011-12-10 Thread John Ladasky
On Dec 10, 10:38 am, Andrew Berg wrote: > On 12/10/2011 11:53 AM, John Ladasky wrote:> Why did you specify Python > 2.7.2, instead of the 2.7.6 version that is > > being offered to me by Ubuntu Software Center?  Does it matter? > > There is no Python 2.7.6. I think you have it confused with the v

Re: Multiprocessing bug, is information ever omitted from a traceback?

2011-12-10 Thread Chris Angelico
On Sun, Dec 11, 2011 at 5:38 AM, Andrew Berg wrote: > On 12/10/2011 11:53 AM, John Ladasky wrote: >> Why did you specify Python 2.7.2, instead of the 2.7.6 version that is >> being offered to me by Ubuntu Software Center?  Does it matter? > There is no Python 2.7.6. I think you have it confused wi

Re: WeakValueDict and threadsafety

2011-12-10 Thread 88888 Dihedral
On Sunday, December 11, 2011 1:56:38 AM UTC+8, Darren Dale wrote: > On Dec 10, 11:19 am, Duncan Booth > wrote: > > Darren Dale wrote: > > > I'm concerned that this is not actually thread-safe. When I no longer > > > hold strong references to an instance of data, at some point the > > > garbage co

Re: Multiprocessing bug, is information ever omitted from a traceback?

2011-12-10 Thread Andrew Berg
On 12/10/2011 11:53 AM, John Ladasky wrote: > Why did you specify Python 2.7.2, instead of the 2.7.6 version that is > being offered to me by Ubuntu Software Center? Does it matter? There is no Python 2.7.6. I think you have it confused with the version 2.7.2-6. If I'm not mistaken, that appended

Re: WeakValueDict and threadsafety

2011-12-10 Thread Darren Dale
On Dec 10, 11:19 am, Duncan Booth wrote: > Darren Dale wrote: > > I'm concerned that this is not actually thread-safe. When I no longer > > hold strong references to an instance of data, at some point the > > garbage collector will kick in and remove that entry from my registry. > > How can I ens

Re: Multiprocessing bug, is information ever omitted from a traceback?

2011-12-10 Thread John Ladasky
On Dec 9, 9:00 pm, Terry Reedy wrote: > On 12/9/2011 6:14 PM, John Ladasky wrote: > > >http://groups.google.com/group/comp.lang.python/browse_frm/thread/751... > > > I'm programming in Python 2.6 on Ubuntu Linux 10.10, if it matters. > > It might, as many bugs have been fixed since. > Can you try

Re: how to test attribute existence of feedparser objects

2011-12-10 Thread Steven D'Aprano
On Sat, 10 Dec 2011 09:19:31 -0800, xDog Walker wrote: > Use standard Python dictionary functions such as has_key to test whether > an element exists. Idiomatic Python code today no longer uses has_key. # Was: d.feed.has_key('title') # Now preferred 'title' in d.feed -- Steven -- http://ma

Re: how to test attribute existence of feedparser objects

2011-12-10 Thread xDog Walker
On Thursday 2011 December 08 01:34, HansPeter wrote: > Hi, > > While using the feedparser library for downloading RSS feeds some of > the blog entries seem to have no title. > > File "build\bdist.win32\egg\feedparser.py", line 382, in __getattr__ > AttributeError: object has no attribute 'title' >

Re: WeakValueDict and threadsafety

2011-12-10 Thread Duncan Booth
Darren Dale wrote: > I'm concerned that this is not actually thread-safe. When I no longer > hold strong references to an instance of data, at some point the > garbage collector will kick in and remove that entry from my registry. > How can I ensure the garbage collection process does not modify

Re: I love the decorator in Python!!!

2011-12-10 Thread 88888 Dihedral
Wrap functions to yield is somewhat like a sub-threading in Erlang. -- http://mail.python.org/mailman/listinfo/python-list

Re: I love the decorator in Python!!!

2011-12-10 Thread 88888 Dihedral
Just wrap the exec() to spawn for fun. -- http://mail.python.org/mailman/listinfo/python-list

Re: Obtaining user information

2011-12-10 Thread Tim Chase
On 12/10/11 01:37, Cameron Simpson wrote: On 09Dec2011 19:44, Tim Chase wrote: | Currently I can get the currently-logged-in-userid via | getpass.getuser() which would yield something like "tchase". _If_ you're on a terminal. _And_ that's exactly what you want. Personally I need to the name of

WeakValueDict and threadsafety

2011-12-10 Thread Darren Dale
I am using a WeakValueDict in a way that is nearly identical to the example at the end of http://docs.python.org/library/weakref.html?highlight=weakref#example , where "an application can use objects IDs to retrieve objects that it has seen before. The IDs of the objects can then be used in other

Re: Python 2 or 3

2011-12-10 Thread Enrico 'Henryx' Bianchi
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Steven D'Aprano wrote: > RHEL supports Python 3, it just doesn't provide Python 3. True, but as you say later, the only method is to recompile. So, if I want to use Python 3 in a production environment like RHEL, I need: - A development environmen

Re: Buffering of sys.stdout and sys.stderr in python3 (and documentation)

2011-12-10 Thread Geoff Bache
Hi Terry, > The difference from 2.x should be in What's New in 3.0, except that the > new i/o module is in 2.6, so it was not exactly new. The io module existed in 2.6, but it was not used by default for standard output and standard error. The only mention of this in "What's New in 3.0" is in the

Re: Obtaining user information

2011-12-10 Thread Cameron Simpson
On 10Dec2011 08:43, Hans Mulder wrote: | On 10/12/11 02:44:48, Tim Chase wrote: | >Currently I can get the currently-logged-in-userid via getpass.getuser() | >which would yield something like "tchase". | > | >Is there a cross-platform way to get the full username (such as from the | >GECOS field o