2 funny Py2.3 Issues: 'datetime', string.join()

Andrew Dalke adalke at mindspring.com
Tue Aug 19 19:17:49 EDT 2003


Rami A. Kishek:
> string.  However, wouldn't it make more sense if the "join" mehtod
> actually belonged to the List object, since it primarily operates on
> lists?

http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.096.htp

> 2) I had a difficult time trying to subclass the new datetime.date
> class.  I basically had written something similar for my own
> applications, and now want to convert my class to take advantage of the
> 'datetime.date' class.

See the documentation for __new__

>>> class MyDT(datetime.datetime):
...    def __new__(cls, year, month = None, day = None):
...       if isinstance(year, tuple):
...          year, month, day = year
...       return datetime.datetime(year, month, day)
...
>>> MyDT( (2003, 8, 19) )
datetime.datetime(2003, 8, 19, 0, 0)
>>>

You'll need to use __new__ for any immutable object.

                    Andrew
                    dalke at dalkescientific.com






More information about the Python-list mailing list