exsh error inside imported file

  • 0
  • 1
  • Question
  • Updated 1 year ago
  • Answered
  • (Edited)
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.

File Name: ImportedFile.py

def showVlan():
exsh.clicmd('show vlan', xml=True)

File Name: main.py

import importedFile

if __name__ == '__main__':


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
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?
Photo of bw447


  • 864 Points 500 badge 2x thumb

Posted 1 year ago

  • 0
  • 1
Photo of Dave Hammers

Dave Hammers, Dir SW Engineering

  • 3,362 Points 3k badge 2x thumb
You will have to add:
import exsh
to ImportedFile.py

exsh is automatically included in the file specified by run script file.py,
but must be explicitly imported beyond that.
Photo of Kawawa

Kawawa, Employee

  • 2,914 Points 2k badge 2x thumb
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(<exos_command, args>)
Photo of bw447


  • 864 Points 500 badge 2x thumb
@Dave Hammers

Sorry for the late reply, but the import is what I was missing. Didn't know it was explicitly imported.