0

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,

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by felix001
1

maybe something like this:

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

>>> sh int counters errors | i Gi.*/1
Votes + Comments
You were correct.
0

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,

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.