newbe how to create 2 __init__ in a class ?

Paul Prescod paulp at ActiveState.com
Fri Mar 23 20:40:50 EST 2001


(year,month,day,price1,price2,price3) 
or*                                     
(string) "2000/12/28,12.3,56.3,45.3"

> Is it possible te create a class with 2 __init__
> 
> exemple i whant to create a classe with
> (year,month,day,price1,price2,price3)
> or*                                     (string) "2000/12/28,12.3,56.3,45.3"
> 
> in C++ I tell the type but how to do it in python.

StringTypes = types.UnicodeType, types.StringType

class Foo:
    def __init__(self, string_or_year, 
                   month=None, day=None, price1=None, 
                   price2=None, price3=None):
        if month:
		assert day and price1 and price2 and ...
		year = string_or_year
	else:
		assert string_or_year in StringTypes
		year, month, day, price1, price2, price3 = \
			mysplit(sring_or_year)

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook




More information about the Python-list mailing list