exsh error inside imported file
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎09-23-2016 02:51 PM
EXOS version 16.1.1.4 I am working on a couple of python scripts. So far everything is working as planned, however I'm getting an error when I try to create multiple files that can be imported (instead of one big file). Below I will give 2 example files and the error that I'm getting. Example File Name: ImportedFile.py def showVlan(): exsh.clicmd('show vlan', xml=True) File Name: main.py import importedFile if __name__ == '__main__': importedFile.showVlan() Both files are in /usr/local/cfg. When I run main.py I get the following error: Slot-1.21 # run script main.py Traceback (most recent call last): File "/config/main.py", line 6, in importedFile.showVlan() File "/config/importedFile.py", line 4, in showVlan exsh.clicmd('show vlan', xml=True) NameError: global name 'exsh' is not defined Is it not possible to run exsh from an imported file?
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎10-06-2016 02:00 PM
@Dave Hammers Sorry for the late reply, but the import is what I was missing. Didn't know it was explicitly imported.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎09-23-2016 07:31 PM
I think you need to define a variable that can store the output of the command output, otherwise where does all that output go when it is retrieved?
variable = exsh.clicmd()
variable = exsh.clicmd(
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
‎09-23-2016 03:17 PM
You will have to add:
import exshto ImportedFile.py
exsh is automatically included in the file specified by run script file.py,
but must be explicitly imported beyond that.
import exshto ImportedFile.py
exsh is automatically included in the file specified by run script file.py,
but must be explicitly imported beyond that.
