找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3622|回复: 3

[已解决] python简明中文编写python文本的数据备份

2

主题

8

帖子

8

积分

贫民

积分
8
huafen 发表于 2016-10-27 22:05:01 | 显示全部楼层 |阅读模式
代码:
import os
import time
source = ['D:\Desktop\phy.txt']
target_dir = 'D:\sublime text'
today = target_dir + time.strftime('%Y%m%d')
now = time.strftime('%H%M%S')

if not os.path.exists(today):
    os.mkdir(today)
    print('sucessfully created directory',today)
target = today + os.sep + now + '.rar'
rar_command = 'C:\Program Files\WinRAR\Rar.exe''a%s%s%(target,''.join(source))'
if os.system(rar_command) == 0:
    print('successful back up to',target)
else:
    print('failed')


为什么会跳转到
sucessfully created directory D:\sublime text20161027
failed
[Finished in 3.3s]
  为什么会变成failed,而不是successful back up to',target?



回复

使用道具 举报

0

主题

24

帖子

24

积分

贫民

积分
24
leftloveu 发表于 2016-10-28 15:13:30 | 显示全部楼层
你的rar_command拼接有错。你把拼接的内容都已经放到了string里面,怎么可能拼成一个正确的命令呢?正确的格式应该是这样:

  1. rar_command = 'C:\Program Files\WinRAR\Rar.exe a %s %s' % (target,''.join(source))
复制代码
回复 支持 1 反对 0

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2016-10-30 19:28:43 | 显示全部楼层
leftloveu 发表于 2016-10-28 15:13
你的rar_command拼接有错。你把拼接的内容都已经放到了string里面,怎么可能拼成一个正确的命令呢?正确的 ...

支持
python3.4.4, win10
回复 支持 反对

使用道具 举报

50

主题

1057

帖子

1108

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1108

活跃会员热心会员最佳导师默默耕耘突出贡献优秀版主荣誉管理论坛元老

blueelwang 发表于 2016-10-31 15:41:51 | 显示全部楼层
leftloveu 发表于 2016-10-28 15:13
你的rar_command拼接有错。你把拼接的内容都已经放到了string里面,怎么可能拼成一个正确的命令呢?正确的 ...

这个问题貌似发过一贴了, 我也这样回复的, 为何又出现一贴呢?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表