[PLUG] Rudimentary python help needed
Paul Mullen
pm at nellump.net
Wed Jan 22 18:41:00 UTC 2014
On Wed, Jan 22, 2014 at 09:33:32AM -0800, Denis Heidtmann wrote:
> I import my module (a file of a few lines of simple stuff), edit the file,
> then attempt to reload and get an error. I have to quit python, restart
> python to get the revised file. Can I get some clues here?
>
> parents at R2D4:~/Documents/Denis/Python$ python
> Python 2.7.3 (default, Sep 26 2013, 20:03:06)
> [GCC 4.6.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from pins_init import*
> >>> cols #test to illustrate that the code was read
> 5
> >>> reload(pins_init)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'pins_init' is not defined
> >>>
reload() fails here because it expects an actual object as its
argument (not just an object name). Since you used "from pins_init
import *", there is no pins_init object in your local namespace.
Instead, every object in pins_init's namespace is now in your local
namespace. You'll have to "import pins_init" before you can reload,
and then you'll need to "from pins_init import *" all over again.
E.g.:
from pins_init import *
# You edit your module's source. Time passes...
import pins_init
reload(pins_init)
from pins_init import *
Recommended reading material:
http://effbot.org/zone/import-confusion.htm
If you expect to spend more time with Python, it's worth subscribing
to the PDX Python mailing list:
https://mail.python.org/mailman/listinfo/portland
--
Paul Mullen
More information about the PLUG
mailing list