Still the __new__ hell ...

Bruno Desthuilliers bruno.42.desthuilliers at
Wed Mar 21 11:51:32 CET 2007

Paulo da Silva a écrit :
> Bruno Desthuilliers escreveu:
>> Paulo da Silva a écrit :
> ...
>>> class MyDate(date):
>>>     def __new__(cls,year,month=None,day=None):
>>>         if type(year) is str:
>> And what if it's a unicode string ?
>> The correct idiom here is:
>>                  if isinstance(year, basestring):
> Thanks.
> If I do type(year) I get either int or str (may be unicode for unicode
> strings) but never anything like basestring.

It's an abstract class.

> As a relatively inexperient
> in python, how could I know that a 'string' is an instance of
> basestring?

By reading this newsgroup ?-)

> x=u"xxxxxx"; help(x) says this is unicode based on
> basestring but help does not "work" for x="xxxxxxxx".


> May be the python tutorial should be upgraded to include these new
> concepts. Also covering the basics of __init__/__new__ (why have both?)

It's a long story. But it's a GoodThing(tm) IMVHO.

More information about the Python-list mailing list