Hi,
Try this:
Code:
#!/usr/bin/python
import time, datetime, os
today = datetime.date.today() # get today's date as a datetime type
todaystr = today.isoformat() # get string representation: YYYY-MM-DD
# from a datetime type.
os.mkdir(todaystr)
Hint: When things don't work as you expect they should in Python the keyword type can save a lot of frustration. Example:
Code:
Python 2.5.1 (r251:54863, Jul 31 2008, 23:17:40)
[GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time, datetime, os
>>> today = datetime.date.today()
>>> os.mkdir(today)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: coercing to Unicode: need string or buffer, datetime.date found
>>> type(today)
<type 'datetime.date'>
>>> todaystr = today.isoformat()
>>> type(todaystr)
<type 'str'>
>>> print todaystr
2009-02-02
>>>
Bookmarks