<p>我写了一个脚本并保存为测试.py(代码如下所示)。当我从脚本运行它时(运行模块5),我在pythonshell中得到结果。你知道吗</p>
<p>但是我尝试了许多在线的建议,让它从pythonshell运行,但是失败了(下面粘贴了一个错误)。你知道吗</p>
<p>如何从pythonshell运行python脚本?
我运行的Python版本是3.7.3和Windows。你知道吗</p>
<pre><code>#!/usr/bin/python3
print(" Hello, world!")
exec(open(test.py).read())
</code></pre>
<p>输出:</p>
<pre><code>Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
exec(open(test.py).read())
NameError: name 'test' is not defined
</code></pre>