I want to reload()
my module in the shell (or in the script) and i am getting an error.
I change the content of my class defnClass which is in the file def_class.py and want to reload
it, but get the exception:
NameError: name 'def_class' is not defined.
The file is in the directory where i have started the shell. Why am i getting this error?
PS: If i restart the shell everything works of course fine.
my code:
class defnClass:
d = 33.45
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def add(self):
return self.a + self.b + self.c
def mult(self):
return self.a * self.b * self.c
def sub(self):
return self.a - self.b - self.c
def div(self, n):
return 12 / n
I then change this code after having used it, to the following:
class defnClass:
d = 33.45
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
def add(self):
return self.a + self.b + self.c + self.div(3)
def mult(self):
return self.a * self.b * self.c
def sub(self):
return self.a - self.b - self.c
def div(self, n):
return 12 / n
Then i try to import the new version in the shell after having saved it with reload(def_class)
which results in the following:
>>> reload(def_class)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'def_class' is not defined
I have started the python-shell from inside the directory where the def_class.py file is.