strftime() argument 1 must be str, not unicode

Tim Roberts timr at probo.com
Thu May 8 03:09:02 EDT 2008


"Andrii V. Mishkovskyi" <mishok13 at gmail.com> wrote:

>2008/5/7 Alexandr N Zamaraev <tonal at promsoft.ru>:
>> Subj is bag?
>>
>>  Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit
>> (Intel)] on win32
>>  Type "help", "copyright", "credits" or "license" for more information.
>>  >>> from datetime import datetime
>>  >>> datetime.today().strftime('%Y_%m_%d %H_%M_%S.csv')
>>  '2008_05_07 12_30_22.csv'
>>  >>> datetime.today().strftime(u'%Y_%m_%d %H_%M_%S.csv')
>>  Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>>  TypeError: strftime() argument 1 must be str, not unicode
>
>Unicode and str objects are not the same. Why do you think that this
>is a bug?

I think that's a perfectly reasonable thing to expect.  At the risk of
over-generalization, there is no good reason why, by this point in time,
all of the standard library routines that accept strings shouldn't also
accept Unicode strings.

It's the duck typing principle.  Unicode strings look, walk, and talk like
regular strings.  An error like this is not intuitive.
-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the Python-list mailing list