Classes - instance/class, methods/members, inheritance and best p ractices

Evan Jones EvanJ at eyron.com
Wed May 2 11:04:22 EDT 2001


Hiya,

I have just started learning Python and was just hoping someone could help
set things straight in my head on user defined classes.

So far as I understand from the docs an instance variable should be
initialized by the __init__ method; an instance method is simply defined in
the class definition; class variables are added to the class definition but
there are no class methods.  In addition I understand that there is no
'constructor' chaining, so that if you are inheriting from some base
classes, when you instantiate the super class the __init__ methods don't get
called from the sub classes.

So what I have been doing is to create each class in a file of its own and
add function definitions to that file to act as 'class' methods, and
constructor chaining I have been doing by hand like:

class Base:
	__init__(self):
		self.init_Base()

	init_Base(self):
		#etc ...

class Super(Base):
	__init__(self):
		self.init_Super()

	init_Super(self):
				self.init_Base()
		#etc ...

So if any one could correct me if I'm wrong, or let me know what the
accepted best practices for 'class methods' and 'constructor chaining' are,
I'd be very grateful.

Cheers
Evan






More information about the Python-list mailing list