开发者

Python: appending a variable to Popen

When i try to carry out the code below i get the error "unsu开发者_如何学编程pported operand type(s) for %: 'list' and 'str'"

from subprocess import Popen
z = '10000'
Popen(["formatdb", "-p", "T", "-i", "%s.txt"] % (z)).wait()

How would I insert my variable z into the name of my text file?


% should immediately follow the string that's being formatted, and you don't need parens around the z. Like so:

Popen(["formatdb", "-p", "T", "-i", "%s.txt" % z]).wait()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜