Pycharm中 import 引入同級文件失敗,如下所示:
“This inspection detects names that should resolve but don't. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Top-level and class-level items are supported better than instance items.”
在同一個文件夾 (rlso4_afterSample)下的各個 python 文件,在 “generate_item_session.py” 中import read_from_file 出現了問題,下划紅色波浪線。即引用失敗。
1、嘗試在前面加 “ from . ” ,依然不行:盡管沒有提示紅色波浪線了,但運行時出錯了:
3、嘗試使用 from .input 等:
原先:
改后:
然而,,運行時依然會 報錯::
4、最后,嘗試把from后面的 . 去掉,並將對應的文件改為類文件。
盡管仍然有紅色波浪線,但是運行不出錯了,,