[Tutor] "classmethods"

Christian Meesters meesters at uni-mainz.de
Fri May 20 10:22:34 CEST 2005


Hi

I've asked a similar question before, but still I have to admit that I 
didn't find a solution with this particular problem here:

Imaging you have a class with a certain __init__ function like:
class MyClass:
	def __init__(parameter1, parameter2=default,*args,**kwargs):
		#handle all input

And a member function like:
	def fromFile(cls,path):
		adict = {}
		alist = []
		#...
		#some part to read a file and to process data

Now, how do I create an instance of MyClass when calling: x = 
MyClass.fromfile(path) ? When I have a line

		return parameter1,parameter2,...,d

in fromFile, a tuple is returned, which is not quite what I want. Is 
there a way to make fromFile a true classmethod?

Any hint would be greatly appreciated.

Regards,
Christian



More information about the Tutor mailing list