[Tutor] incomprehension in type of classes.

Cedric BRINER work at infomaniak.ch
Fri Apr 22 13:44:28 CEST 2005


hello,

I have 2 questions. the first one is maybe not directly related to python (it's about eric3), and the second oneis about what the command `type' give back for two instances

in my python code I have changed some classes like the following

from (I):

class CYear:
   def __init__(self, year):
      self.__year=year
      print str(self.__year)             <<---(*)
      print 'dir of: '+str(dir(self))
      print 'type of: '+str(type(self))
   def __str__(self):
      return "we are in "+str(self.year)


to (IIOB):

class CYearDerived(int):
   def __init__(self, year):
      super(CYearDerived,self).__init__(year)
      self.__year=year
      print str(self.__year)            <<-----(*OB)
      print 'dir of: '+str( dir(self) )
      print 'type of: '+str(type(self))
   def __str__(self):
      return "we are in "+super(CYearDerived,self).__str__()



Question 1 (about eric3)
----------
with the change from I to II, when I debug the code, I don't see the self arborescence (that you find in Window Debug Browser>>Local Variables) which shows you the attributes of the class that you are currently debugging in.


Quesion 2
---------
why type of (CYear(2005))
<type 'instance'>

and type(CYearDerived)
<class '__main__.CYearDerived'>

doesn't give the same type ???

-- 

Cedric BRINER


More information about the Tutor mailing list