On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers > > [snip] > >And what if it's a unicode string ? >The correct idiom here is: > if isinstance(year, basestring): > >> year,month,day=map(int,string.split(year,'-')) > year, month, day = map(int, year.split('-'))
And what if it's another kind of string? The correct idiom is: try: parts = year.split('-') except AttributeError: # Handle int case else: year, month, day = map(int, parts) > >> if year < 100: >> year += 2000 >> return date.__new__(cls,year,month,day) >> >(snip) >-- >http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list