20 Apr 2012
April 20, 2012

NameError: Jython

April 20, 2012 Blog, Jython, WebSphere, WebSphere Application Server 0 Comment

Error when importing aJython script library (module)  into another Jython module I get the following error.

c:\scripts>"C:/Program Files/IBM/WebSphere7/AppServer1/profiles/Dmgr01/bin/wsadmin.bat" -username wasadmin -password wasadmin -lang jython -f "C:/scripts/clusterAndServer_test.py"
WASX7209I: Connected to process "dmgr" on node myCellManager01 using SOAP connector;  The type of process is: DeploymentManager
WASX7017E: Exception received while running file "C:/scripts/clusterAndServer_test.py"; exception information: com.ibm.bsf.BSFException: exception from Jython:
Traceback (innermost last):
  File "", line 2, in ?
  File "C:\scripts\.\clusterAndServer.py", line 637, in ?
NameError: Usage

Reason:
Well it is because I had a piece of code specified to handle the library if it is ever called as a main as opposed to an import and I referred to a mfunction called Udage() which did not exist.


#---------------------------------------------------------------------
# Name: anonymous
# Role: Verify that the script was executed, not imported
# Note: main (implied) script entry point
#---------------------------------------------------------------------
if __name__ in [ '__main__', 'main' ] :
  print "INFO: In main entry point for this library"
else :
  Usage( __name__ )

Solution:
I pasted in the “Usage” Function for example:

#---------------------------------------------------------------------
# Name: Usage()
# Role: Display script usage information
#---------------------------------------------------------------------
def Usage( cmdName ) :
    print __doc__ % locals()
    sys.exit()

#---------------------------------------------------------------------
# Name: anonymous
# Role: Verify that the script was executed, not imported
# Note: main (implied) script entry point
#---------------------------------------------------------------------
if __name__ in [ '__main__', 'main' ] :
  print "INFO: In main entry point for this library"
else :
  Usage( __name__ )
Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply