cancel
Showing results for 
Search instead for 
Did you mean: 

exsh error inside imported file

exsh error inside imported file

bw447
New Contributor III
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

bw447
New Contributor III
@Dave Hammers Sorry for the late reply, but the import is what I was missing. Didn't know it was explicitly imported.

Kawawa
Extreme Employee
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()

Dave_Hammers
Extreme Employee
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.
GTM-P2G8KFN