Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2218
| Date | 2011-03-30 11:10 +0200 |
|---|---|
| From | Jean-Michel Pichavant <jeanmichel@sequans.com> |
| Subject | Re: delete namespaces |
| References | <UtydnQbv7-6IGQ_QnZ2dnUVZ_hWdnZ2d@insightbb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10.1301476243.2990.python-list@python.org> (permalink) |
monkeys paw wrote: > How do i delete a module namespace once it has been imported? > > I use > > import banner > > Then i make a modification to banner.py. When i import it again, > the new changes are not reflected. Is there a global variable i can > modify? It depends on what you want to achieve. 1/ if you want to re-import your module because it contains User data that may have been updated, one way is to make sure all you definitions are at the module level and use the execfile statement. ofc the file is executed, so it can be done only in a trusted environment. 2/ if you want to reload your module because you changed the code and want to test it, the best way to do it is to write a test file that will do all the tests so that restarting the test is cheap. Testing from a newly created python process is always the best solution, if available. 3/ if you want to do the 2/ but require a painful long prologue to your test, then you may want to use the builtin reload. Use it with care, because any existing object created from the previous module will not be affected, they'll still hold the previous code. "reload" solves some problems, but bring others, especially for the newcomer. JM
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
delete namespaces monkeys paw <monkey@joemoney.net> - 2011-03-29 21:14 -0400
Re: delete namespaces Raymond Hettinger <python@rcn.com> - 2011-03-29 18:32 -0700
Re: delete namespaces Tim Chase <python.list@tim.thechases.com> - 2011-03-29 20:41 -0500
Re: delete namespaces Terry Reedy <tjreedy@udel.edu> - 2011-03-30 00:57 -0400
Re: delete namespaces Raymond Hettinger <python@rcn.com> - 2011-03-30 17:11 -0700
Re: delete namespaces Chris Angelico <rosuav@gmail.com> - 2011-03-31 14:06 +1100
Re: delete namespaces Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-03-30 11:10 +0200
Re: delete namespaces Terry Reedy <tjreedy@udel.edu> - 2011-03-30 15:03 -0400
Re: delete namespaces Tim Golden <mail@timgolden.me.uk> - 2011-03-30 20:08 +0100
Re: delete namespaces Ritesh Nadhani <riteshn@gmail.com> - 2011-03-30 21:22 -0700
Re: delete namespaces rusi <rustompmody@gmail.com> - 2011-03-30 22:11 -0700
csiph-web