Import File But Reports Error Nameerror: Name 'something' Is Not Defined
testa.py class A: s1 = 333 __age = 0 def __init__(self,age ): self.__age=age return def __del__(self): return #private def _
Solution 1:
Solution 2:
Remember this:
Doing: import mymodule
does not import the whole methods and attributes of mymodule
to the namespace, so you will need to refer to mymodule
, everytime you need a method or attribute from it, using the .
notation, example:
x = mymodule.mymethod()
However, if you use:
from mymodule import *
This will bring every method and attribute of mymodule
into the namespace and they are available directly, so you don't need to refer to mymodule
each time you need to call one of its method or attribute, example:
from mymodule import *
x = mymethod() #mymethod being a method from mymodule
You can also import specific method if you don't want to bring the whole module:
from mymodule import myMethod
For further details, read the Python docs:
Post a Comment for "Import File But Reports Error Nameerror: Name 'something' Is Not Defined"