我正在使用p4 Python模块尝试打开几个文件进行编辑。基本上,我有一个从txt文档中获取的文件列表。然后对列表中的每一项进行一些格式化,并将这些项附加到空列表中。我的方法并不是最有效的,但我只是尝试在优化之前使其工作。
edit_files = []
with open('C:\\Users\\rgriffin\Desktop\\replace.txt', 'r' )as f:
for line in f:
l = line.partition(',')[0]
e = l.replace('#(', '')
r = e.replace('U:\\', '//Stream/main/')
q= r.replace('\\', '/')
edit_files.append(q)
f.close
for i in edit_files:
p4.run("edit" , i) 通过这段代码,我得到了一个错误:
警告:'"//Stream/main/Data/anims/stuff/char/Emotion_Angry.hkx“-文件不在客户端。
如果我把最后一行改成这个..。
p4.run("edit" , "//Stream/main/Data/anims/stuff/char/Emotion_Angry.hkx") 文件将按预期的方式签出。我做了一个类型检查,i是一个字符串。
输入数据:
#("U:\Data\anims\stuff\char\Emotion_Angry_Partial.hkx", "u:\Assets\Actors\stuff\char\Animation\char_Idle.max")发布于 2013-07-16 21:02:14
在下面的命令中,末尾有引号。一定要把它们移走。似乎也有空行。变化
for i in edit_files:
p4.run("edit" , i) 至
for i in edit_files:
f=i.replace('"','').strip()
if len(f)>0:
print "Opening ["+f+"]"
p4.run("edit" , f) 或者一个班轮
[p4.run("edit" , i.replace('"','').strip()) for i in edit_files if i.strip()]或者您可能希望更改填充代码本身:使用:
with open('C:\\Users\\rgriffin\Desktop\\replace.txt', 'r' )as f:
for line in f:
l = line.partition(',')[0].replace('#(', '').replace('U:\\', '//Stream/main/').replace('\\', '/').replace('"', '').strip()
if len(l)>0:
edit_files.append(l)
f.closehttps://stackoverflow.com/questions/17686370
复制相似问题