del on modules

Steve Holden sholden at holdenweb.com
Mon Jan 14 08:07:49 EST 2002


"rihad" <rihad at mail.ru> wrote in message
news:1f854u881pk0ovmj8u1684g4n6ri21b3na at 4ax.com...
> I have...
>
> d:\dir0\
>     __init__.py
>     mod.py
>
> mod.py has var = 6
>
> now I say...
>
> C:\Python22>python
> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import sys
> >>> sys.path.append('d:\\')
> >>> import dir0.mod
> >>> dir0.mod.var
> 6
> >>> del dir0.mod
> >>> import dir0.mod
> >>> dir0.mod.var
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'module' object has no attribute 'mod'
> >>> dir(dir0.mod)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> AttributeError: 'module' object has no attribute 'mod'
> >>> dir(dir0)
> ['__builtins__', '__doc__', '__file__', '__name__', '__path__']
> >>>
>
>
> Where did mod go? OK, I delled it, but why doesn't import dir0.mod
> bring it back to life?
>
Maybe you should try reload(dir0.mod)

The import statement, repeated on an already-imported module, does not
execute the module code again.

regards
 Steve
--
http://www.holdenweb.com/







More information about the Python-list mailing list