namespace and reloading (was Re: PythonWin IDE sucks!)

Huaiyu Zhu hzhu at users.sourceforge.net
Wed Nov 1 23:01:59 CET 2000


On Tue, 31 Oct 2000 15:37:15 -0500, Jason Cunliffe <jasonic at nomadicsltd.com>
wrote: 

>...surely these are not the same?
>
>>>> from module import object
>puts 'object' directly into the namespace doesn't it, so one would use
>>>> object
>
>But in the second case
>
>>>> import module
>
>means that one would then use
>>>> module.object

They are not the same.  The former get object into you current name space so
it is quicker to look up but difficult to update.  The latter leaves it in
module name space so it's less clutter, and easier to update.

>I suppose my question is:
>
>When you use  >>> from module import object
>#forget import module compeletely for the moment
>
>how  do you do reload()?

AFAIK, you can't do directly.  You have to import module; reload(module);
from module import object.

>It seems to me the cleanest way is to use the more verbose "import module"
>syntax.
>But there are many famous exceptions, such as wxPython Tutorials
>http://www.wxpython.org/tut-part1.php
>
>encourages
>>>> from wxPython.wx import *

Some packages are written with this intention in mind, so the names are less
likely to confict.  Since these are ready-made packages you generally
wouldn't want to reload anyway.

I think that once you do "from module import *" there's no way to find out
which name in your current name space came from which module.  (Somebody
please confirm this as I'm not completely sure.) So if you want to update
them all you have to redo "from ...".

Huaiyu



More information about the Python-list mailing list