Learn How We Can Help You Keep Teleworkers Protected During the COVID-19 Crisis

Automation Scripts

Reply
Highlighted
Accepted Solution

Trouble with substring in python

Techie
Posts: 7
215     0

Hello,

 

Has anyone tried to manipulate strings in python with NetMRI?

 

Basically, I'm trying to pull the first 4 characters of the device's name and stored it in a new variable. NetMRI gives me an error but the same python code works in a another Linux environment. Any workaround for this?

 

This code works fine in another Linux platform:

 

>>> device = 'baltrouter1'
>>> print(device[:4].upper())
BALT
>>>

 

This python code (2nd print command) doesn't run in NetMRI:

 

mydevice = 'baltrouter1'
print(mydevice)
print(mydevice[:4].upper())

 

NetMRI Status Logs:

+++ Looking up device information ...................................... OK
+++ Looking up device information ...................................... OK
+++ Looking up job specification information ........................... OK
+++ Loading ccs file ................................................... OK

+++ Script: script_xyz
+++ Script-Filter ...................................................... MATCH
baltrouter1

*** ERROR: Error 'Traceback (most recent call last):
File "<stdin>", line 170, in <module>
TypeError: 'str' object is not callable
Python script has returned 1 value
' ***

Highlighted

Re: Trouble with substring in python

Adviser
Posts: 423
216     0

I just ran the following and got these results:

 

Code:

# Create NetMRI context manager. It will close session after execution
with NetMRIEasy(**defaults) as easy:
    mydevice = 'baltrouter1'
    print(mydevice)
    print(mydevice[:4].upper())

 

 

Results:

+++ Script: f 
+++ Script-Filter ...................................................... MATCH
baltrouter1
BALT
+++ Looking up device information ...................................... OK

I'm running 7.4.2

Follow me on LinkedIn: https://www.linkedin.com/in/sifbaksh
Twitter: https://twitter.com/sifbaksh
Showing results for 
Search instead for 
Do you mean 

Recommended for You