Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31046
| Date | 2012-10-09 12:10 -0400 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: surprising behaviour of global dictionaries |
| References | <40ac555b-71c2-445e-814b-6bd1d037dbee@googlegroups.com> <mailman.2006.1349796256.27098.python-list@python.org> <b8a3d0c5-d6ba-42ef-a706-708b9148b594@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2009.1349799062.27098.python-list@python.org> (permalink) |
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 not find that name in the cache and import another instance >> >> of the module, with puzzling effects > Actually I usually never use the main script as a library, this is why I never experience this puzzling behavior before. But now it is clear, thanks. More generally, you should arrange your imports so that there are no cycles. If module/script "a" imports "b", directly or indirectly, "b" should not try to import "a." Move the common code to a third place, and import it from both "a" and from "b". The other symptoms you can get are more subtle than this one, but just as surprising. -- DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
surprising behaviour of global dictionaries Michele Simionato <michele.simionato@gmail.com> - 2012-10-09 08:08 -0700
Re: surprising behaviour of global dictionaries Peter Otten <__peter__@web.de> - 2012-10-09 17:24 +0200
Re: surprising behaviour of global dictionaries Michele Simionato <michele.simionato@gmail.com> - 2012-10-09 08:36 -0700
Re: surprising behaviour of global dictionaries Dave Angel <d@davea.name> - 2012-10-09 12:10 -0400
Re: surprising behaviour of global dictionaries Michele Simionato <michele.simionato@gmail.com> - 2012-10-09 08:36 -0700
Re: surprising behaviour of global dictionaries Grant Edwards <invalid@invalid.invalid> - 2012-10-09 15:53 +0000
Re: surprising behaviour of global dictionaries Peter Otten <__peter__@web.de> - 2012-10-09 19:45 +0200
csiph-web