似乎他们在Python 3中取消了通过删除快速加载脚本的所有简单方法 execfile()
有没有一个明显的选择我错过了?
当我运行终端然后访问python3 shell时,我可以使用import运行文件或模块,但如果我尝试再次运行它,则没有任何反应.
之前我看过这个问题:[ 每次对脚本进行更改时,都需要在终端中重启python
我阅读了文档:[ https://docs.python.org/3/tutorial/modules.html#executing-modules-as-scripts] [1 ]
但两者都在讨论重新启动模块中的单个功能.我在谈论重新运行整个文件.我将此代码包含在我的文件末尾,但仍然没有发生任何事情
if __name__ == "__main__":
pass
Run Code Online (Sandbox Code Playgroud)
更新: 我在评论中运行文件后,这就是我得到的:
Ms-MBP:mine M$ python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> python python_file.py
File "<stdin>", line 1
python python_file.py
^
SyntaxError: invalid syntax
>>>
Run Code Online (Sandbox Code Playgroud)