0

I'm trying to pass a tuple after an if statement in a for loop. I'm not sure what I'm doing wrong.

procs = ((1432, 'var', 'var2', procname),(1556, 'var4', 'var5', othername),) 

def killprocs(procname):
    print "searching for %s" % procname      
    for i in procs:
        if procname in i[3]:
            print "proc %s matches." % i
        else:
            pass

I get:

Traceback (most recent call last):
  File "processkiller.py", line 59, in <module>
    killprocs(args.procname)
  File "processkiller.py", line 24, in killprocs
    print "proc %s matches." % i
TypeError: not all arguments converted during string formatting

1 Answer 1

3

str.__mod__() is detecting that the right-hand operand is a tuple and so is attempting to use all elements in the formatting. To fix this, create a 1-tuple containing the tuple instead.

print "proc %s matches." % (i,)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.