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

软件和网站开发以及相关技术探讨
回复
头像
c43035
帖子: 724
注册时间: 2008-10-22 14:29
联系:

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

#1

帖子 c43035 » 2014-05-30 16:49

这是代码:

代码: 全选

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

代码: 全选

www.bashell.org
亲,走过路过,不要错过
头像
lainme
论坛版主
帖子: 7805
注册时间: 2008-09-13 19:17
系统: Arch Linux (x86_64)
联系:

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

#2

帖子 lainme » 2014-05-30 16:58

代码: 全选

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

代码: 全选

rar_command = "winrar '%s' '%s'" %(target, ' '.join (source))
头像
c43035
帖子: 724
注册时间: 2008-10-22 14:29
联系:

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

#3

帖子 c43035 » 2014-05-30 17:04

lainme 写了:

代码: 全选

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

代码: 全选

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

代码: 全选

www.bashell.org
亲,走过路过,不要错过
回复