Delete a function

Peter Otten __peter__ at web.de
Wed Mar 21 18:26:57 CET 2007


gtb wrote:

> On Mar 21, 11:37 am, Steve Holden <s... at holdenweb.com> wrote:
>> gtb wrote:
>> > After a function has been imported to a shell how may it be deleted so
>> > that after editing it can reloaded anew?
>>
>> Use the built-in reload() function to reload the module that defines the
>> function.
>>
>> regards
>>   Steve
>> --
>> Steve Holden       +44 150 684 7255  +1 800 494 3119
>> Holden Web LLC/Ltd          http://www.holdenweb.com
>> Skype: holdenweb    http://del.icio.us/steve.holden
>> Recent Ramblings      http://holdenweb.blogspot.com
> 
> Thanks, tried that now and get nameError: with the following.
> 
> import sys
> sys.path.append("c:\maxq\testScripts")

That's an interesting directory name:

>>> print "c:\maxq\testScripts"
c:\maxq estScripts

 
> from CompactTest import CompactTest
> from compactLogin import dvlogin

The above line puts dvlogin into the current namespace, not compactLogin;
therefore
 
> reload(compactLogin)

compactLogin is undefined in the reload() call. You need

import compactLogin # still the old module because it's in the module cache
reload(compactLogin)
from compactLogin import dvlogin # update the function
del compactLogin # optional

Peter




More information about the Python-list mailing list