Re: surprising behaviour of global dictionaries

2012-10-09 Thread Peter Otten
Grant Edwards wrote: > On 2012-10-09, Peter Otten <__pete...@web.de> wrote: > >> Welcome to python -- this is a trap every newbie falls into ;) >> >> Seriously, you shouldn't use the main script as a library; > > There must be something wrong with me. It never even occurred to me > to try to im

Re: surprising behaviour of global dictionaries

2012-10-09 Thread Dave Angel
On 10/09/2012 11:36 AM, Michele Simionato wrote: > On Tuesday, October 9, 2012 5:24:17 PM UTC+2, Peter Otten wrote: >> Seriously, you shouldn't use the main script as a library; it is put into >> >> the sys.modules cache under the "__main__" key. Subsequent imports under its >> >> real name will

Re: surprising behaviour of global dictionaries

2012-10-09 Thread Grant Edwards
On 2012-10-09, Peter Otten <__pete...@web.de> wrote: > Welcome to python -- this is a trap every newbie falls into ;) > > Seriously, you shouldn't use the main script as a library; There must be something wrong with me. It never even occurred to me to try to import a file from within that same f

Re: surprising behaviour of global dictionaries

2012-10-09 Thread Michele Simionato
On Tuesday, October 9, 2012 5:24:17 PM UTC+2, Peter Otten wrote: > Seriously, you shouldn't use the main script as a library; it is put into > > the sys.modules cache under the "__main__" key. Subsequent imports under its > > real name will not find that name in the cache and import another ins

Re: surprising behaviour of global dictionaries

2012-10-09 Thread Peter Otten
Michele Simionato wrote: > I have the following module implementing a registry of functions with a > decorator: > > $ cat x.py > registry = {} # global dictionary > > def dec(func): > registry[func.__name__] = func > print registry, id(registry) > return func > > if __name__ == '__m

surprising behaviour of global dictionaries

2012-10-09 Thread Michele Simionato
I have the following module implementing a registry of functions with a decorator: $ cat x.py registry = {} # global dictionary def dec(func): registry[func.__name__] = func print registry, id(registry) return func if __name__ == '__main__': import xlib print registry, id(re