2009-01-13 168 views
-2

這是我的代碼:幫助中FileNotFoundException異常-python

try: 
    import clr, sys 
    from xml.dom.minidom import parse 
    import datetime 
    sys.path.append("C:\\teest") 
    clr.AddReference("TCdll") 
    from ClassLibrary1 import Class1 
    cl = Class1() 
except (ImportError) : 
    print "Module may not be existing " 

我TCdll是在C:\ test.I只是把它作爲C:\ teest知道錯誤。

例外是這樣的:

Traceback (most recent call last): 
     File "C:/Python25/13thjan/PSE.py", line 8, in <module> 
     clr.AddReference("TCdll") 
    FileNotFoundException: Unable to find assembly 'TCdll'. 
     at Python.Runtime.CLRModule.AddReference(String name) 

如何處理這個異常?

幫助需要立即

回答

4

你需要找出clr.AddReference如何映射到一個文件名。

編輯:

我想你問如何抓住從AddReference呼叫例外呢?

替換:

clr.AddReference("TCdll") 

有:

try: 
    clr.AddReference("TCdll") 
except FileNotFoundException,e: 
    print "Failed to find reference",e 
    sys.exit(1)