Importing variables gives attribute error python -


this done in python 2.7.3:

x.py:

import y global path_variable path_variable = "a_path" y.procedure() 

y.py:

import x def procedure():     return x.path_variable 

now when run x odd error:

attributeerror: 'module' object has no attribute 'path_variable' 

why this? far know python allows import variables. doing wrong?

i believe issue of circular dependency. basically, can fix code want rethink package design such don't have 2 modules import 1 another.

also, don't need declare path_variable global used when changing variables in global scope while inside local scope , use discouraged in python.

x.py

import y path_variable = "a_path"  if __name__ == "__main__":     y.procedure() 

y.py

import x def procedure():     return x.path_variable 

Comments

Popular posts from this blog

asp.net mvc 3 - Using mvc3, I need to add a username/password to the sql connection string at runtime -

kineticjs - draw multiple lines and delete individual line -

thumbnails - jQuery image rotate on hover -