Search code examples
webspherejythonwsadmin

Trying to call wsadmin objects from a method that is defined in another file gives a NameError


I have a script named test.py which is the main script that imports all definitions from def.py.

def.py

def test():
  print AdminApp.list() #Prints the applications installed
#EndDef

and the test.py

import sys
from def import *
test()

This throws a NameError stating that the AdminApp object cannot be identified as a valid function, keyword or variable.

WASX7093I: Issuing message: "WASX7017E: Exception received while running file "test.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "<string>", line 10, in ?
  File "/opt/home/echkaay/wsadmin/test.py", line 3, in ?
NameError: AdminApp 

Any direction?


Solution

  • As I have globalised the Admin Objects in my definitions.py script, for them to be available throughout, rather then importing them using from definitions import *, I used the execfile.

    execfile(scriptPath + "/jython/definitions.py")
    

    That did it.