classmethod and instance method

Xavier Morel xavier.morel at masklinn.net
Thu Feb 2 15:47:31 EST 2006


andychambers2002 at yahoo.co.uk wrote:
> Hi,
> 
> I'm trying to write a method that needs to know both the class name and
> the  instance details
> 
> Any suggestions?
> 

What's the point of using a classmethod and an explicit cls argument 
when you can get the class object from the instance itself?

 >>> class Test(object):
	def meth(self):
		print self
		print self.__class__
		print type(self)

		
 >>> test = Test()
 >>> test.meth()
<__main__.Test object at 0x00FA1710>
<class '__main__.Test'>
<class '__main__.Test'>
 >>>



More information about the Python-list mailing list