ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I fount it hard to find a good thread title. I hope the code is self explainatory:
Code:
# one.py
variable = "value"
from two import *
if __name__ == '__main__': print_value()
# two.py
def print_value():
print variable
--
python one.py
Traceback (most recent call last):
File "one.py", line 4, in ?
if __name__ == '__main__': print_value()
File "/home/sybec/test/two.py", line 2, in print_value
print variable
NameError: global name 'variable' is not defined
Importing two.py into the local name space of one.py makes objects from two.py available inside one.py.
But this does not mean that it also works the other way around. two.py still doesn't know about objects from one.py (like [i]variable[i]).
It is probably possible to do with some 'python trick', but then two.py will depend on one.py. This is not what people want generally, because then doesn't make sense to have seperate modules in the first place.
Or, purhaps this was what you were looking for?
Code:
variable = "value"
from two import *
if __name__ == '__main__': print_value(variable)
The *problem* is that my application has a number of "n" settings which will be used by various functions (some will use "all" the settings, some only a few, some no settings at all). Now.. assuming my settings are:
I don't know how "efficient" it would be to pass "n" settings via arguments to a function. Obviously, if I do this, there's no need for "variable" to be global. I could store the settings in a dictionary.. or make a class which has them as attributes, and add a few methods which manipulate these settings one way or the other. But then, I'd have only one object belonging to this class. So would it be super-flu or something?
I could store the settings in a dictionary.. or make a class which has them as attributes, and add a few methods which manipulate these settings one way or the other.
Good ideas IMHO.
Quote:
Originally Posted by introuble
But then, I'd have only one object belonging to this class. So would it be super-flu or something?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.