Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Python is a <a href="http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29" rel="nofollow">garbage collected</a> language. When you do <code>del MyClass</code>, you do not actually delete the 'class object' (classes are objects too), but you only remove the 'name' <code>MyClass</code> from the current namespace, which is some sort of reference to the class object. Any object stays alive as long as it is referenced by something. Since instances reference their own class, the class will stay alive as long as there is at least one instance alive.</p> <p>One thing to be careful about is when you redefine a class (e.g. on the command line):</p> <pre><code>In [1]: class C(object): ...: def hello(self): ...: print 'I am an instance of the old class' In [2]: c = C() In [3]: c.hello() I am an instance of the old class In [4]: class C(object): # define new class and point C to it ...: def hello(self): ...: print 'I am an instance of the new class' In [5]: c.hello() # the old object does not magically become a new one I am an instance of the old class In [6]: c = C() # point c to new object, old class and object are now garbage In [7]: c.hello() I am an instance of the new class </code></pre> <p>Any existing instances of the old class will continue to have the old behavior, which sort of makes sense considering the things I mentioned. The relation between name-spaces and objects is a bit particular to python, but is not that hard once you get it. A good explanation is given <a href="http://effbot.org/zone/python-objects.htm" rel="nofollow">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload