Python 自帶的 IDLE 就可以做到了,你開啟一個 python file 後 run module,你會發現主控台上可以操控 file 中的 variable Pycharm 的部分我自己試了一下,你進到 Run/Edit Configurations... 然後把 Interpreter options 加入 -i 的選項: 之後運行 script 完畢,shell 會 keep 在那邊不會結束 其實不需要 ide 就可以做到你想做的了 假設你有一個 python script test.py a = 5 b = [1, 2, 3] 直接用: $ python -i test.py 運行 test.py 完畢後,Python 會停在 console 中可以繼續互動 或是用: $ python 開啟 python shell 後,用 import 匯入 test 並執行,接著你就可以操控 variable 了: >>> from test import * >>> a 5 >>> b [1, 2, 3] 這也有同樣效果 我回答過的問題: Python-QA
Python 自帶的 IDLE 就可以做到了,你開啟一個 python file 後 run module,你會發現主控台上可以操控 file 中的 variable
Pycharm 的部分我自己試了一下,你進到
Run/Edit Configurations...
然後把
Interpreter options
加入-i
的選項:之後運行 script 完畢,shell 會 keep 在那邊不會結束
其實不需要 ide 就可以做到你想做的了
假設你有一個 python script
test.py
直接用:
運行
test.py
完畢後,Python 會停在 console 中可以繼續互動或是用:
開啟 python shell 後,用
import
匯入 test 並執行,接著你就可以操控 variable 了:這也有同樣效果
我回答過的問題: Python-QA