莪最近在查看别人的源码、发现他定义的字符串前面都有个r、是什么意思
时间:2011-07-19
来源:互联网
本帖最后由 klobodnf 于 2011-07-19 11:52 编辑
莪最近在查看别人的源码、发现他定义的字符串前面都有个r、是什么意思
zip = r"E:\program\7-Zip\7z.exe"
flFileList = open(r"G:\impl\build\path.txt", 'r')
为了帮助大家理解、莪把代码完整的贴出来吧
复制代码
莪最近在查看别人的源码、发现他定义的字符串前面都有个r、是什么意思
zip = r"E:\program\7-Zip\7z.exe"
flFileList = open(r"G:\impl\build\path.txt", 'r')
为了帮助大家理解、莪把代码完整的贴出来吧
- #!/usr/bin/python
- # encoding:utf-8
- # Filename: copyFileFromList.py
-
- import os
- import sys
- import time
- import shutil
-
- zip = r"E:\program\7-Zip\7z.exe"
- flFileList = open(r"G:\impl\build\path.txt", 'r')
- flFileSourceHistory = open(r"G:\impl\build\SourceDirHistory.txt", 'w')
- dirZipDest = r"I:\pre-realease\201107"
-
- dtDestRoot = {}
- dtDestRoot['zoshow'] = r'G:\impl\zip\zoshow'
- dtDestRoot['xiutuan'] = r'G:\impl\zip\xiutuan'
- dtDestRoot['tuanhuo'] = r'G:\impl\zip\tuanhuo'
- dtDestRoot['365wine'] = r'G:\impl\zip\365wine'
- dtDestRoot['search'] = r'G:\impl\zip\search'
- dtDestRoot['newcms'] = r'G:\impl\zip\newcms'
- dtDestRoot['zuc'] = r'G:\impl\zip\zuc'
- dtDestRoot['thexiucms'] = r'G:\impl\zip\thexiucms'
- sSelectProject = """
- Please select a project:
- zoshow
- xiutuan
- tuanhuo
- 365wine
- search
- newcms
- zuc
- thexiucms
- Enter choice: """
-
- sourceRoot = raw_input('enter source root: ')
- if not os.path.exists(sourceRoot):
- print '文件夹不存在: ' + sourceRoot
- sys.exit()
-
- # 检查是否存在目标文件夹(destRoot),如果存在则重命名备份,不存在则新建文件夹。
- destRootChoice = raw_input(sSelectProject)
- if destRootChoice in dtDestRoot.keys():
- destRoot = dtDestRoot[destRootChoice]
- if os.path.exists(destRoot):
- os.rename(destRoot, destRoot + '_bak' + time.strftime('%Y%m%d') + '-' + time.strftime('%H%M'))
- os.mkdir(destRoot)
- else:
- os.mkdir(destRoot)
- else:
- print 'no such project'
- sys.exit()
- #destRoot = raw_input('enter dest root: ')
- #if os.path.exists(destRoot):
- # os.rename(destRoot, destRoot + '_bak' + time.strftime('%Y%m%d') + '-' + time.strftime('%H%M'))
- # os.mkdir(destRoot)
- #else:
- # os.mkdir(destRoot)
-
- ltFile = flFileList.readlines()
- for singleFile in ltFile:
- singleFile = singleFile.strip()
- if (os.path.exists(singleFile) and os.path.isfile(singleFile)):
- sourceFolder = os.path.split(singleFile)[0]
- destFolder = destRoot + sourceFolder.replace(sourceRoot, '')
- if not os.path.exists(destFolder):
- os.makedirs(destFolder)
- shutil.copy2(singleFile, destFolder)
- #print singleFile, destFolder
- flFileSourceHistory.close()
- flFileList.close()
-
- dir2Zip = destRoot
- flZip = os.path.split(destRoot)[0] + os.sep + os.path.split(destRoot)[1] + '-' + time.strftime('%Y%m%d') + '-' + time.strftime('%H%M') + '.zip'
- zip_command = "%s a -tzip %s %s" % (zip, flZip, dir2Zip)
- os.system(zip_command)
-
- # 移动到I:\pre-realease\
- os.rename(flZip, dirZipDest + os.sep + os.path.split(flZip)[1])
- print "move %s to \n%s" % (flZip, dirZipDest + os.sep + os.path.split(flZip)[1])
作者: klobodnf 发布时间: 2011-07-19
明白了、是强制禁止转义的意思
作者: klobodnf 发布时间: 2011-07-19
回复 klobodnf
多余,用不着r。open(‘G:/impl/build/path.txt’, 'r')就行。
多余,用不着r。open(‘G:/impl/build/path.txt’, 'r')就行。
作者: 106033177 发布时间: 2011-07-19
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28