[英]Addressing directory in python
I make this program and it has an error. 我制作了这个程序,它有一个错误。 I thinks it's related to the addressing.
我认为这与寻址有关。
import os
def renamefi():
filist=os.listdir(r"D:\Data\Personal-Education\Personal Work\Python Learning Project\Soppurted Files\prank")
savepath=os.getcwd()
os.chdir=(r"D:\Data\Personal-Education\Personal Work\Python Learning Project\Soppurted Files\prank")
for finame in filist :
os.renames(finame, finame.strip("012345678"))
renamefi()
and this is the error: 这是错误:
Traceback (most recent call last): File "D:\\Data\\Personal-Education\\Personal Work\\Python Learning Project\\Udacity-2_Rename.py", line 9, in renamefi() File "D:\\Data\\Personal-Education\\Personal Work\\Python Learning Project\\Udacity-2_Rename.py", line 8, in renamefi os.renames(finame, finame.strip("012345678")) File "C:\\Python34\\lib\\os.py", line 282, in renames rename(old, new) FileNotFoundError: [WinError 2] The system cannot find the file specified: '.DS_Store' -> '.DS_Store' [Finished in 0.1s]
追溯(最近一次通话):文件“ D:\\ Data \\ Personal-Education \\ Personal Work \\ Python学习项目\\ Udacity-2_Rename.py”,第9行,renamefi()文件“ D:\\ Data \\ Personal-Education \\ Personal Work \\ Python学习项目\\ Udacity-2_Rename.py“,第8行,在namedfi os.renames(finame,finame.strip(” 012345678“))文件“ C:\\ Python34 \\ lib \\ os.py”中,行282,在重命名中重命名(旧,新)FileNotFoundError:[WinError 2]系统找不到指定的文件:'.DS_Store'->'.DS_Store'[以0.1秒完成。
editor screen shot: http://s3.picofile.com/file/8201944476/address.jpg 编辑器屏幕截图: http : //s3.picofile.com/file/8201944476/address.jpg
You need to indent: 您需要缩进:
for finame in filist :
os.renames(finame, finame.strip("012345678")
Should be 应该
for finame in filist:
os.renames(finame, finame.strip("012345678")
And it's also missing the end parenthesis: 而且它也缺少结尾括号:
for finame in filist :
os.renames(finame, finame.strip("012345678"))
Also you forgot a backslash in one of the filenames. 您也忘记了其中一个文件名中的反斜杠。 It should be "D:\\Data".
它应该是“ D:\\ Data”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.