Im using pexpect to output some terminal commands, but im facing the following issue.

The code is

porttype = "Gi"

print
expectSw.sendline ("sh int counters errors | i %.*/1 ") % porttype
expectSw.expect ('.*#')
print expectSw.after

But when I run the code i get ...

Traceback (most recent call last):
  File "./script", line 30, in <module>
    expectSw.sendline ("sh int counters errors | i %.*/1 ") % porttype
TypeError: unsupported operand type(s) for %: 'int' and 'str'

It looks like it maybe trying to calculate the string. Can anyone shed any light onto this ?

Thanks,

maybe something like this:

porttype = "Gi"
print "sh int counters errors | i %s.*/1 " % porttype

>>> sh int counters errors | i Gi.*/1
commented: You were correct. +4

After some further searching I found the issue. The syntax was a little incorrect it should of been :

expectSw.sendline ("sh int counters errors | i %s.*/1 " % porttype)

Thanks,