strftime() argument 1 must be str, not unicode
Andrii V. Mishkovskyi
mishok13 at gmail.com
Wed May 7 03:54:40 EDT 2008
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? Anyway, you can always use 'encode' method of unicode
objects:
In [2]: datetime.today().strftime('%Y-%m-%d %H-%M-%S.csv')
Out[2]: '2008-05-07 10-49-24.csv'
In [3]: datetime.today().strftime(u'%Y-%m-%d %H-%M-%S.csv')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/mishok/doc/python/<ipython console> in <module>()
TypeError: strftime() argument 1 must be str, not unicode
In [4]: datetime.today().strftime(u'%Y-%m-%d %H-%M-%S.csv'.encode('utf-8'))
Out[4]: '2008-05-07 10-51-19.csv'
No offence, but have you read the tutorial?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
--
Wbr, Andrii Mishkovskyi.
He's got a heart of a little child, and he keeps it in a jar on his desk.
More information about the Python-list
mailing list