差異處
這裏顯示兩個版本的差異處。
python:basic:import_class [2016/12/07 12:00] tony [Problem] |
python:basic:import_class [2023/06/25 09:48] |
||
---|---|---|---|
行 1: | 行 1: | ||
- | {{tag>python}} | ||
- | ====== Import Class - 'module' object is not callable ====== | ||
- | ===== Problem ===== | ||
- | 這算是初學者問題。範例專案結構如下: | ||
- | <code bash> | ||
- | example/ | ||
- | __init_.py | ||
- | Test.py | ||
- | main.py | ||
- | </code> | ||
- | Test.py中有一個class叫Test,而main.py我這樣使用它: | ||
- | <code python> | ||
- | from example import Test | ||
- | |||
- | test = Test() | ||
- | </code> | ||
- | 在執行時,會出現TypeError: 'module' object is not callable。 | ||
- | ===== How to? ===== | ||
- | |||
- | ===== Reference ===== | ||
- | - [[http://stackoverflow.com/questions/4534438/typeerror-module-object-is-not-callable|typeerror-module-object-is-not-callable]] | ||
- | |||