Question

im tring to capture a part from a string im giving it the location i want in integers but it keep telling me its tuple i don't know why im using pexpect to get a version from network device

ssh_device.sendline('/info/sys/general')
ssh_device.expect('(?i)FLASH')
ver_long = ssh_device.before
print ver_long
print "\nthe ver_long type is "
print type(ver_long)
location = int(ver_long.find('('))
print "\nthe location type is "
print type(location)
print location
ver_short = ver_long[location-25,location]
print ver_short

the output is :

System Information at 0:05:17 Sat Jan 3, 2070 Time zone: America/US/Pacific Daylight Savings Time Status: Enabled

BNT Layer 2/3 Copper Gigabit Ethernet Switch Module for IBM BladeCenter

Switch has been up for 2 days, 8 hours, 5 minutes and 17 seconds. Last boot: (reset from Telnet/SSH)

MAC Address: 00:22:00:63:4a:00 Management IP Address (if 128): 10.106.12.25 Software Version 5.2.3.1 (

the ver_long type is 'str'

the location type is 'int' 294 Traceback (most recent call last): File "version.py", line 83, in ver_short = ver_long[location-25,location] TypeError: string indices must be >integers, not tuple

notice that the type is int !!

Was it helpful?

Solution

Use a colon, not a comma to define the start and end of a slice:

ver_short = ver_long[location-25:location]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top