The directory structure is :
ga/ :
PP.py
this.py
that.py
tripathi/:
nn.py # contains function net
neuron.py #contains function node
aicc.py # contains function AICC
blah.py
variable.py
__init__.py
I am trying to use 'tripathi' directory as a module. Hence, __init__.py
#__init__.py
from nn import net
from neuron import node
from aicc import AICC
#variable.py
def initialise (): #to initialise global variables
global globe1, globe2, globe3
globe1 = 8
globe2 = [1,2,3,4,5]
globe3 = "bakar"
The file variable.py
contains some global variables to be used in this.py
, that.py
, and PP.py
#this.py
from tripathi import node
from tripathi import AICC #function AICC in aicc.py
from tripathi import variables #file variables.py
variables.initialise() #all global variables initialised
this_one = variables.globe1
Now, that.py has
#that.py
import this
AttributeError : 'module' object has no attribute 'globe1'
Why is there an Error? Does import this
statement (in that.py
) not import all the modules imported in this.py
?
Edit: I am using IPython notebook.
Using the global keyword is not enough. You have to declare the variable on module level: