473,385 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 2083
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 answer after two days of searching. For the record, my...
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 evolving. This can be a problem when, ad example,...
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 variable 'config.modsel' points to a particular...
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 interfaces it presents. Currently, I set some...
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' def main():
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" that defines some paths, variables etc. without...
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 this: from X import * and then did my testing....
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 task ImportError: No module named task/ Thank...
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 find variables to *unbind*. Once a variable is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.