如何在Spyder控制台中执行Python 3.3脚本,哪个有变量?
我的示例代码(C:/test/myfile.py)是
from sys import argv
script, first, second, third = argv
print("The script is called:", script)
print("Your first variable is:", first)
print("Your second variable is:", second)
print("Your third variable is:", third)
我试过exec(open(“C:\ test \ myfile.py”)。read()) - 我得到的错误是“ValueError:需要多于1个值来解包。我想提供变量first =“1st”,second =“2nd”,third =“3rd”。如何编写exec()以便它可以处理输入?
我正在使用Python 3.3,64位安装,Windows操作系统,安装:WinPython。
答案 0 :(得分:13)
你需要去
Run > Configuration per file
(或点击Ctrl+F6
),然后在出现的对话框中,您需要检查
Command line options
并写(例如)那里
1 2 3
关闭此对话框并点击F5
后,您将看到您期望的输出。
注意:请记住,这些命令行选项是作为文件运行配置的一部分在Spyder重启之间保存的,因此如果您想要更改它们,则需要再次点击Ctrl+F6
答案 1 :(得分:3)
Spyder的IPython控制台的作用是:
在[1]中:runfile('C:/yourfolder/myfile.py',args='one two three')