Still the __new__ hell ...

Paulo da Silva psdasilvaX at esotericaX.ptX
Mon Mar 19 11:27:12 EDT 2007


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. As a relatively inexperient
in python, how could I know that a 'string' is an instance of
basestring? 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?)
would be nice.

Paulo



More information about the Python-list mailing list