Header Only - DO NOT REMOVE - Extreme Networks

exsh error inside imported file

Userlevel 2
EXOS version 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

Userlevel 5
You will have to add:
import exsh[/code]to ImportedFile.py

exsh is automatically included in the file specified by run script file.py,
but must be explicitly imported beyond that.
Userlevel 5
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()[/code]
Userlevel 2
@Dave Hammers Sorry for the late reply, but the import is what I was missing. Didn't know it was explicitly imported.