Re: Still the __new__ hell ...
Paulo da Silva a écrit :
It's an abstract class.
By reading this newsgroup ?-)
help(str)
It's a long story. But it's a GoodThing(tm) IMVHO.
Paulo da Silva a écrit :
Bruno Desthuilliers escreveu:
...
>
>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.
>Paulo da Silva a écrit :
>
>>class MyDate(date):
>> def __new__(cls,yea r,month=None,da y=None):
>> if type(year) is str:
>> def __new__(cls,yea r,month=None,da y=None):
>> if type(year) is str:
>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?
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".
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?)
concepts. Also covering the basics of __init__/__new__ (why have both?)
Comment