This is not a duplicate question, only marked as so by someone who doesn't even care to read the two carefully.
OK, I give up -- I am learning Python and am still a beginner, but someone just want to show that he is unwilling to help, and doesn't allow other to help either, because the problem get closed and nobody can answer anymore. Once again, They are total different problems (because that one is about using math.pi
in module1.cool()
which can be easily solved by doing from math import pi
in module1
), at least to me, and even now, because I still cannot make the connection as I am learning Python and am still a beginner. If you think it is a duplicate, please show me how, not just arbitrarily say so without leaving any clue. That's not helping at all.
I have a dozen of global variables that I want to pass to my functions, previously defined in iPython notebook, and works just fine; now defined inside a separate file and everything broke down. I need a solution, but neither of the suggested "duplicated" can answer that. I give up.
I had been putting my global variables and my Functions definitions in iPython notebook like the following:
global_var = 'foo'
def ex1():
local_var = 'bar'
print global_var
print local_var
ex1()
print global_var
I.e., I define a global variables and can use it from my functions definitions in iPython notebook. This is OK.
However, when I move the functions definitions into a separated file (as it is getting too long and I don't want to copy it around to different iPython notebooks each time), I can't access my global variables from the same function any longer. I got:
NameError: name 'global_var' is not defined
The only difference is that I put the functions definitions into a separated file. Then use
from mylib import *
So, it is still possible for my functions to access my global variables defined in iPython notebook please?
UPDATE 1: I saw that (the dulicate candidate now removed), but that one's first answer is more on functions, SQL cursor, using second modules, yada, yada, which I really can't grasp and relate. Let's give this simple question a simple answer instead. E.g., the second answer is from globals import *
, that's what I'm using.
UPDATE 2: About "Python: Namespaces with Module Imports", if you look closely, the problem is about using math.pi
in module1.cool()
, a total different problem which can be easily solved by doing from math import pi
in module1
. Well, at least to me they are total different problems, because I still cannot make the connection as I am learning Python and am still a beginner. If you think it is a duplicate, please show me how, not just arbitrarily say so without helping the poor soul who is still lost. Gee, no matter how many time I edit it, that wrongfully-accusing "[duplicate]" sign is still there. Gee. Again, If you think it is a duplicate, please show me how, not just arbitrarily say so without leaving any clue.