分页: 1 / 1

求助!按教程写的代码,报错(python 3.3)

发表于 : 2014-05-30 16:49
c43035
这是代码:

代码: 全选

import os
import time

# 1. The files and directories to be backed up are specified in a list.
source = [r'D:\python', r'D:\python2']
# If you are using linux, use source = ['/home/python', '/home/python2] or something like that

# 2. The backup must be stored in a main backup directory
target_dir = r'D:\pybackup'

# 3. The files are backed up into a rar file.
# 4. The name of the rar archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.rar'

# 5. We use the rar command to put the files in a rar archive
rar_command = "winrar '%s' '%s'"(target, ' '.join (source))

# 6. Run the backup
if os.system(rar_command) == 0:
    print('successful backup to', target)
else:
    print('backup failed')

以下是报错信息:

代码: 全选

Traceback (most recent call last):
  File "D:\python\backup_ver1.py", line 19, in <module>
    rar_command = "winrar '%s' '%s'"(target, ' '.join (source))
TypeError: 'str' object is not callable

Re: 求助!按教程写的代码,报错(python 3.3)

发表于 : 2014-05-30 16:58
lainme

代码: 全选

rar_command = "winrar '%s' '%s'"(target, ' '.join (source))
改成

代码: 全选

rar_command = "winrar '%s' '%s'" %(target, ' '.join (source))

Re: 求助!按教程写的代码,报错(python 3.3)

发表于 : 2014-05-30 17:04
c43035
lainme 写了:

代码: 全选

rar_command = "winrar '%s' '%s'"(target, ' '.join (source))
改成

代码: 全选

rar_command = "winrar '%s' '%s'" %(target, ' '.join (source))
:em11 感谢