我正在阅读Python的一个字节,其中包含了一些关于如何编写脚本来压缩文件的内容。我已经检查了我的代码好几次了,但仍然找不到bug的所在。我想知道我的code.BTW怎么了,我用的是Mac,谢谢。
import os
import time
source=[r'/Users/username/Desktop/test.txt']
target_dir=r'/Users/username/Desktop/backup'
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'
print target
zip_command="zip -qr'%s'%s"%(target,''.join(source))
if os.system(zip_command)==0:
print 'successful backup to',target
else:
print 'backup failed'发布于 2017-12-17 10:04:17
您在zip参数中缺少空格。您所看到的错误是由您的路径被解释为选项列表造成的,因为您拥有:
zip -qr/Users/username/Desktop/test.txt...instead of:
zip -qr /Users/username/Desktop/test.txt替换这一行:
zip_command="zip -qr'%s'%s"%(target,''.join(source))...by这个:
zip_command="zip -qr '%s' %s"%(target,''.join(source))https://stackoverflow.com/questions/47854002
复制相似问题