初学者求救:关于mkdir()

初学者求救:关于mkdir()

今天看《简明python教程》
按照上面的程序抄了 下来,可是就是不能运行。
源程序如下:
#!/usr/bin/python
# Filename: backup_ver4.py

import os
import time

# 1. The files and directories to be backed up are specified in a list.
source = ['/root/zhang', '/root/软件']

# 2. The backup must be stored in a main backup directory
target_dir = '/root/backup/'

# 3. The files are backed up into a zip file.
# 4. The current day is the name of the subdirectory in the main directory

today = target_dir + time.strftime('%Y%m%d')

# The current time is the name of the zip archive

now = time.strftime('%H%M%S')

# Take a comment from the user to create the name of the zip file

comment = raw_input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
        target = today + os.sep + now + '.zip'
else:
        target = today + os.sep + now + '_' + \
        comment.replace(' ', '_') + '.zip'
   
# Create the subdirectory if it isn't already there

if not os.path.exists(today):
        os.mkdir(today) #创建一个目录
        print 'Successfully created directory', today
# 5. We use the zip command (in Unix/Linux) to put the files in a zip archive

zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))

# Run the backup

if os.system(zip_command) == 0:
        print 'Successful backup to', target
else:
        print 'Backup FAILED'


报出的错误为:
[root@localhost python]# python v4.py
sys:1: DeprecationWarning: Non-ASCII character '\xe8' in file v4.py on line 8, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
Enter a comment --> zhang1
Traceback (most recent call last):
  File "v4.py", line 34, in ?
    os.mkdir(today)
OSError: [Errno 2] No such file or directory: '/root/backup/20070406'
处理中文出了问题了。
mkdir不能创建多级目录,检查一下是否要创建的目录的父目录都存在。另外使用 os.makedirs 可以创建多级目录。
是mkdir的 问题,如果mkdir -p的 话可以建立多极目录。
呵呵。谢谢,两位的帮助阿!
不要搞错,命令行与程序中的函数是不同的。