How do I import a variable from another module?

Steven D'Aprano steve at REMOVEME.cybersource.com.au
Thu May 3 23:00:52 EDT 2007


On Thu, 03 May 2007 18:27:12 -0700, noagbodjivictor wrote:

> I have a variable names actions in a module named qt_actions.py
> 
> Well this is what I get:
>>>> import qt_actions
>>>> qt_actions.actions
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'actions'

The error is clear -- you *don't* have an attribute named actions in the
module.

I'm going to guess that you've imported the module, then edited it, then
imported it again. That doesn't help, because imported modules are cached.
You need to reload(qt_actions).

Either that, or you've got two modules named qt_actions, and only one of
them has a variable 'actions'. The first module in the PYTHONPATH is
imported.

Or, you're mistaken about having such a variable. 

But my money is on the first one. Use reload(qt_actions).

-- 
Steven D'Aprano 




More information about the Python-list mailing list