tags:

views:

32

answers:

1

When i try to carry out the code below i get the error "unsupported 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?

+3  A: 

% 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()
sdolan
You don't need the parens around z.
Ned Batchelder
@Ned: Yup, updated my answer. Thanks.
sdolan