I have a class and I want to import a def function by doing:
import <file>
but when I try to call it, it says that the def can not be found. I also tried:
from <file> import <def>
but then it says global name 'x' is not defined.
So how can I do this?
Edit:
Here is a example of what I am trying to do. In file1.py I have:
var = "hi"
class a:
def __init__(self):
self.b()
import file2
a()
and in file2.py I have:
def b(self):
print(var)
it is just giving me a error though.
file; you import a module, or names contained in a module.import modulename, notimport filename.py. You'll need to add a more concrete example to illustrate your problem better.