2013-04-26 1 views
0

def.py에서 모든 정의를 가져 오는 주 스크립트 인 test.py라는 스크립트가 있습니다.다른 파일에 정의 된 메서드에서 wsadmin 개체를 호출하려고하면 NameError가 발생합니다.

def.py

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

test.py

import sys 
from def import * 
test() 

이것은은 AdminApp 오브젝트가 유효한 기능, 키워드 나 변수로 식별 수 없다는 나가서 설명하자면 NameError가 발생합니다 .

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 

방향은?

+0

이제는 -profile 옵션을 사용하여이 호출을 시도하고 Websphere 객체를 초기화하는 init 파일을 전달했습니다. –

답변

-1

은 내가 execfile를 사용 * 가져옵니다.

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

그랬습니다.

0

developerWorks에있는 wsadminlib.py의이 스탠자가 도움이됩니까? 그들에 걸쳐 사용할 수에 대한 차라리 다음 정의에서 사용하여 가져 오기, 내 definitions.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." 
관련 문제