0

我有一个名为 test.py 的脚本,它是从 def.py 导入所有定义的主脚本。

定义文件

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

test.py

import sys
from def import *
test()

这会引发 NameError 指出 AdminApp 对象不能被识别为有效的函数、关键字或变量。

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 

有什么方向吗?

4

2 回答 2

0

developerworks 上 wsadminlib.py 中的这节有帮助吗?

# Provide access to wsadminlib methods when accessed as an import.
# This is benign if wsadminlib is opened with execfile().
# Supports both connected and disconnected operations.
# (ie, works when wsadmin is connected to a running server,
# and works when wsadmin is not connected to a server.)
try:
    AdminConfig = sys._getframe(1).f_locals['AdminConfig']
    AdminApp = sys._getframe(1).f_locals['AdminApp']
    AdminControl = sys._getframe(1).f_locals['AdminControl']
    AdminTask = sys._getframe(1).f_locals['AdminTask']
except:
    print "Warning: Caught exception accessing Admin objects. Continuing."
于 2013-04-27T13:30:22.430 回答
-1

由于我已经在我的 definitions.py 脚本中对管理对象进行了全球化,以便它们始终可用,而不是使用 from definitions import * 导入它们,我使用了 execfile。

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

做到了。

于 2013-04-29T10:30:53.927 回答