Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86263
| References | <aacac55a-6779-4ad3-96f4-5332ff36a365@googlegroups.com> <mcfqeb$5tb$1@dont-email.me> <mailman.19095.1424717125.18130.python-list@python.org> <ac52606e-f85f-4e94-8dac-6556e28821be@googlegroups.com> |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | 2015-02-23 13:39 -0700 |
| Subject | Re: Best practice: Sharing object between different objects |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19100.1424724040.18130.python-list@python.org> (permalink) |
On Mon, Feb 23, 2015 at 1:02 PM, <sohcahtoa82@gmail.com> wrote: > What's REALLY interesting is that this happens: > >>>> import myModule >>>> myModule.myInt > 1 >>>> myModule.myInt = 2 >>>> myModule.myInt > 2 >>>> del myModule >>>> import myModule >>>> myModule.myInt > 2 > > I would REALLY expect that deleting the module object and then re-importing would reset that variable. Even though you deleted the module locally, it's still referenced in the sys.modules cache (as well as in any other place where it might have been imported). That's the place you need to delete it from if you really want to re-execute it. >>> import myModule >>> myModule.myInt 1 >>> myModule.myInt = 2 >>> myModule.myInt 2 >>> import sys >>> del sys.modules['myModule'] >>> import myModule >>> myModule.myInt 1
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best practice: Sharing object between different objects pfranken85@gmail.com - 2015-02-21 04:15 -0800
Re: Best practice: Sharing object between different objects Dave Angel <davea@davea.name> - 2015-02-21 09:28 -0500
Re: Best practice: Sharing object between different objects Paul Rubin <no.email@nospam.invalid> - 2015-02-21 09:18 -0800
Re: Best practice: Sharing object between different objects Rob Gaddi <rgaddi@technologyhighland.invalid> - 2015-02-23 18:10 +0000
Re: Best practice: Sharing object between different objects Michael Torrie <torriem@gmail.com> - 2015-02-23 11:36 -0700
Re: Best practice: Sharing object between different objects sohcahtoa82@gmail.com - 2015-02-23 12:02 -0800
Re: Best practice: Sharing object between different objects Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-23 20:13 +0000
Re: Best practice: Sharing object between different objects Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-23 13:39 -0700
Re: Best practice: Sharing object between different objects Michael Torrie <torriem@gmail.com> - 2015-02-23 14:10 -0700
Re: Best practice: Sharing object between different objects Chris Angelico <rosuav@gmail.com> - 2015-02-24 11:14 +1100
csiph-web