Search code examples
pythonstringpexpect

Python Pexpect: TypeError: unsupported operand type(s) for %: 'int' and 'dict'


When I try to run the following pexpect command i get the error: TypeError: unsupported operand type(s) for %: 'int' and 'dict'. I do not really understand why I am getting this error. When I do a print of the string I am outputting the results are what I expect.

My code:

p.sendline("sudo date -s \"%(easterndate)s\"") % locals()

Print test of the same string:

print "string ouput: " + "sudo date -s \"%(easterndate)s\"" % locals()
    output: sudo date -s "Tue Mar 26 14:25:51 EDT 2013"

Solution

  • It should be:

    p.sendline("sudo date -s \"%(easterndate)s\"" % locals())
    

    Otherwise the % is applied to the result of the sendline call.