Global Variables Over Multiple Source Files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mahem Ones
    New Member
    • Jun 2011
    • 4

    Global Variables Over Multiple Source Files

    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.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Not unless the variable is declared global, which makes it an attribute of the module after the function is called as in:
    Code:
    import xyz
    xyz.f()
    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.

    Comment

    Working...