How do I make a module make use of a variable defined globally in Jupyter-notebook?

16 views Asked by At

So I have a jupyternotebook main.ipynb. I have to submodules named x.py and y.py. x.py contains the line x = 30 and y.py contains the line y = 2*z

I know how I can use the variable defined in the secondary file by using it as an attribute of that file. For instance, in main.ipynb's first cell, I import x and then run print (x.x) it works ok.

Now, in the next cell if I define a variable z= 15. and then I import y.py I get the following err

NameError: name 'z' is not defined

My question is, how do I make the submodule y recognize variable z which is in the global namespace.

0

There are 0 answers