472,330 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

How do I import a variable from another module?

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
4 2006
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dan Williams | last post by:
Hi people I've just joined the Python list and although I'm sure my question must be asked fairly frequently, I have been unable to find an...
16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is...
2
by: David MacQuigg | last post by:
I'm setting up a large hierarchy of module packages and using a variable to select which of many alternative packages to import. For example, the...
17
by: Jacek Generowicz | last post by:
I have a module whose behaviour needs to be configurable. The module needs to decide, the first time it is imported, beteween alternative...
4
by: MackS | last post by:
Hi I'm new to Python, I've read the FAQ but still can't get the following simple example working: # file main_mod.py: global_string = 'abc'...
5
by: Pekka Niiranen | last post by:
Hi there, I have two scripts. The first "main.py" sets some variables and then imports another called "gen.py". The idea is to provide "main.py"...
3
by: John Salerno | last post by:
I understand that after you import something once, you can reload it to pick up new changes. But does reload work with from statements? I tried...
3
by: yinglcs | last post by:
Hi, i have 2 python files in *different directory* , how can I import python functions from 1 python file to another? i get this error: import...
0
by: Gary Herron | last post by:
Dan Yamins wrote: Because loading (and reloading) assigns values to variables (called binding a value in Python), but does not go on a hunt to...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.