Others constructors...
Andrew Dalke
adalke at mindspring.com
Wed Sep 24 15:00:05 EDT 2003
Others constructors...Batista, Facundo:
> but also you have others constructors. For example:
> mydate = datetime.date.today()
> How is this trick implemented in Python?
staticmethod, which is in newer Pythons.
>>> class Date:
... def __init__(self, year, month, day):
... self.year = year
... self.month = month
... self.day = day
... def my_birthday():
... return Date(1970, 8, 22)
... my_birthday = staticmethod(my_birthday)
...
>>> d = Date.my_birthday()
>>> d.year
1970
>>>
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list