差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

Both sides previous revision 前次修改
下次修改
前次修改
python:basic:import_class [2016/12/07 12:00]
tony [Problem]
python:basic:import_class [2023/06/25 09:48] (目前版本)
行 17: 行 17:
 在執行時,會出現TypeError:​ '​module'​ object is not callable。 在執行時,會出現TypeError:​ '​module'​ object is not callable。
 ===== How to? ===== ===== How to? =====
 +在這樣的專案結構下,common資料夾為package名稱,Test.py的Test為模組名稱,其內的class Test就是我要的類別名稱。因此正確的匯入應該是:​ 
 +<code python>​ 
 +from common.Test import Test 
 +</​code>​ 
 +假如Test.py中有其它類別叫Test2,則要使用以下方式匯入:​ 
 +<code python>​ 
 +from common.Test import Test2 
 +</​code>​
 ===== Reference ===== ===== Reference =====
   - [[http://​stackoverflow.com/​questions/​4534438/​typeerror-module-object-is-not-callable|typeerror-module-object-is-not-callable]]   - [[http://​stackoverflow.com/​questions/​4534438/​typeerror-module-object-is-not-callable|typeerror-module-object-is-not-callable]]