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

Global Variables Over Multiple Source Files

P: 4
So basically I can't seem to get global variables in functions I import from a different file.

Also are the only scopes in python classes and functions?
Or is there a way to set your own scopes.
Like in C++ you can put {} brackets anywhere you like.
Jul 31 '11 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Not unless the variable is declared global, which makes it an attribute of the module after the function is called as in:
Expand|Select|Wrap|Line Numbers
  1. import xyz
  2. xyz.f()
  3. xyz.f_var
Why not return the value of the variable? The use of classes with mutable attributes is my preference. That way you can have multiple variables directly accessible.
Jul 31 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.