Connect two source files in python?
Question: I was trying to split
[this](http://www.roguebasin.com/index.php?title=Complete_Roguelike_Tutorial,_using_python%2Blibtcod,_part_13_code)
into some smaller files, but its really hard for me becouse of complicated
class-global_variable-function relations. Is there any way to connect two
files like they were one file in python?

Sorry if this was unclear, i add example of problem:

    
    
    #\a.py
    def print_foo():
        global foo
        print foo
    
    #\main.py
    from a import *
    
    def initialize_values():
        global foo, bar
        foo='abc'
        bar=123
    
    initialize_values()
    print_foo()
    

This causes error "global variable foo not declared" or something like that.


Answer: Python doesn't have truly global variables, only module-level globals. That
is, in `a.print_foo`, the statement `global foo` refers to the variable
`a.foo`. In `main.initialize_values`, `global foo` refers to `main.foo`. When
you call `print_foo`, it tries to print `a.foo`, but that name was never
defined.

You could write in `main.py`

    
    
    import a
    
    def initialize_values():
        global bar  # keep in mind, this is main.bar
        a.foo='abc'
        bar=123
    
    initialize_values()
    a.print_foo()
    

but that raises a question of design: why are you initializing global
variables in the module `a` from a different module?

