Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'test,': 0.04; 'definitions': 0.07; 'python': 0.07; 'builtin': 0.09; 'namespace': 0.09; 'restarting': 0.09; 'solution,': 0.09; 'statement.': 0.09; 'wrote:': 0.14; 'executed,': 0.16; 'monkeys': 0.16; 're-import': 0.16; 'received:192.168.200': 0.16; 'reload': 0.16; 'solves': 0.16; 'subject:delete': 0.16; 'code.': 0.18; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'variable': 0.21; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python-list': 0.22; 'modification': 0.23; 'tests': 0.26; 'environment.': 0.26; 'object': 0.27; 'changed': 0.27; 'testing': 0.28; 'depends': 0.29; 'changes': 0.29; 'cc:addr:python.org': 0.31; "they'll": 0.31; 'import': 0.32; 'done': 0.32; 'created': 0.33; 'module': 0.33; 'test': 0.33; 'received:192': 0.34; 'there': 0.35; 'file': 0.35; 'header:User-Agent:1': 0.35; 'data': 0.37; 'received:192.168': 0.37; 'some': 0.37; 'user': 0.38; 'but': 0.38; 'delete': 0.38; 'hold': 0.39; 'problems,': 0.39; 'how': 0.39; 'best': 0.60; 'bring': 0.62; 'care,': 0.69; 'banner': 0.80; 'achieve.': 0.96 X-IronPort-AV: E=Sophos;i="4.63,267,1299452400"; d="scan'208";a="1166260" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Wed, 30 Mar 2011 11:10:26 +0200 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: monkeys paw Subject: Re: delete namespaces References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1301476243 news.xs4all.nl 41113 [::ffff:82.94.164.166]:49500 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:2218 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