I have defined c:/temp/t.py as follows:
class MyClass(object):
def __init__(self):
self._my_secret_thing = 1
def _i_get(self):
return self._my_secret_thing
def _i_set(self, value):
self._my_secret_thing = value
def _i_delete(self):
print 'neh!'
#del self._my_secret_thing
my_thing = property(_i_get, _i_set, _i_delete,'this document for my_thing')
Then I use Python Shell 2.4.4 as follows:
>> import sys
>>> sys.path.append('c:/temp')
>>> import t
>>> dir(t)
['MyClass', '__author__', '__builtins__', '__doc__', '__file__', '__name__']
>>> t = MyClass()
Traceback (most recent call last):
File "<pyshell#11>", line 1, in -toplevel-
t = MyClass()
NameError: name 'MyClass' is not defined
Question> Why python shell cannot find ‘MyClass’?
You import a module called
t. Because of namespacing, everything defined inthas to be accessed through it.If you want to just get the class and discard everything else in the
tmodule, you can do that like so.