python 文件备份错误
#! c:\python26
# Filename: backup_ver1.py
import os
import time
source=[r'C:\test', r'C:\test1']
target_dir='D:\\back\\'
target=target_dir+time.strftime('%Y%m%d%H%M%S')+'.zip'
zip_command="rar a -r \"%s\" \"%s\"" %(target,''.join(source))
if os.system(zip_command)==0:
print'successful backup to',target
else:
print'backup failed'
在dos下运行,提示“不能读取c:\testc:\test1的内容” ,如果改为“source=r'C:\test'” ,只备份一个目录,可以运行。
不知道怎么解决
''.join(source)
==>
' '.join(source)
记着两个单引号中间是个空格。
如果是空格,在dos运行提示“找不到指定路径”,不能空格的
逻辑有点问题,这个应该能工作:
zip_command="rar a -r \"%s\" \"%s\"" % (target, "\" \"".join(source))
呵呵,和我一样也在学这节呢
{{
相关问答:
像 C 的 scanf() 那样
比如读入 1 2 3 a b c
每次读入一个
下面这个应该是你想要的吧:
Python code:
>>> k = raw_input()
0 0123 ds dsl sd
>>> k
'0 0123 ds dsl sd'
>>> ......
在list中添加一个类的局部变量 这样做是否合法 请看下面例子:
Python code:
class A():
def __init__( self ):
self.__a = 0
self.__b = 'hello'
def get_a( self ):
ret ......
小弟接触python 2个星期了,安装的是python3.1版。
我用的是windows7,想写个调用dll的程序实践。问题来了:
C++代码:
extern "C" int __stdcall test();
int __stdcall te ......
Python code:
class Rectangle:
def __init__(self, width, height):
self.width = width
self.height = height
def paint(self, factory):
point = factory.getPoint()
......