[英]How to call another python file, run it, and replace main.py with the new .py file?
有以下問題的答案:
如何從另一個py文件運行一個py文件?
但是沒有答案告訴如何用最近運行的文件替換 main.py,但仍然是 jeep main.py。 我正在使用 python 3,我的執行命令是這樣的:
exec(open('newfile.py').read())
如何用 newfile.py 替換 main.py,但保留 main.py?
我只是嘗試像這樣創建 first.py:
print('hello world!')
而 second.py 是這樣的:
import first
然后 first.py 將在 second.py 運行的 Python 環境中運行。 但在 first.py __name__
值將是'first'
而不是'__main__'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.