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,

Recommended Answers

All 2 Replies

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,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.