By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

How do I import a variable from another module?

P: n/a
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'

May 4 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
are you sure your variable isn't in some code block that wouldn't be
read on import? Such as:

if __name__ == "__main___":
actions = 1
May 4 '07 #2

P: n/a
On May 3, 9:36 pm, Andy Terrel <andy.ter...@gmail.comwrote:
are you sure your variable isn't in some code block that wouldn't be
read on import? Such as:

if __name__ == "__main___":
actions = 1
No Andy, I have not put the variable in any code block

May 4 '07 #3

P: n/a
On May 4, 6:39 am, noagbodjivic...@gmail.com wrote:
On May 3, 9:36 pm, Andy Terrel <andy.ter...@gmail.comwrote:
are you sure your variable isn't in some code block that wouldn't be
read on import? Such as:
if __name__ == "__main___":
actions = 1

No Andy, I have not put the variable in any code block
Does the variable show up in the dir listing of the module?

ie.
>>import qt_actions
dir(qt_actions)
May 4 '07 #4

P: n/a
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

May 4 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.