Why does an object still work properly without the class
I'm a newbie in Python. After reading some chapters of Python Tutorial
Release 2.7.5, I'm confused about Python scopes and namespaces. This
question may be duplicated because I don't know what to search.
I created a class and an instance. Then I deleted the class using del. But
the instance still works properly. Why?
>>>class MyClass: # define a class
... def greet(self):
... print 'hello'
...
>>>Instan = MyClass() # create an instantiation
>>>Instan
<__main__.MyClass instance at 0x00BBCDC8>
>>>Instan.greet()
hello
>>>dir()
['Instan', 'MyClass', '__builtins__', '__doc__', '__name__', '__package__']
>>>
>>>
>>>del MyClass
>>>dir()
['Instan', '__builtins__', '__doc__', '__name__', '__package__']
>>>Instan
<__main__.MyClass instance at 0x00BBCDC8> # Myclass doesn't exist!
>>>Instan.greet()
hello
I know little about OOP so this question may seem simple. Thanks in advance.
No comments:
Post a Comment