gpt4 book ai didi

python - 在 Python shell 中运行程序

转载 作者:IT老高 更新时间:2023-10-28 20:38:25 25 4
gpt4 key购买 nike

我有一个演示文件:test.py。在 Windows 控制台中,我可以使用以下命令运行该文件:C:\>test.py

如何改为在 Python Shell 中执行文件?

最佳答案

使用 execfile Python 2:

>>> execfile('C:\\test.py')

使用 exec Python 3

>>> exec(open("C:\\test.py").read())

关于python - 在 Python shell 中运行程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7420937/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com