uda*_*day 13 python python-3.x spyder
如何在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)
Run Code Online (Sandbox Code Playgroud)
我试过exec(open("C:\ test\myfile.py").read()) - 我得到的错误是"ValueError:需要多于1个值来解包.我想先提供变量=" 1st",second ="2nd",third ="3rd".如何编写exec()以便它可以处理输入?
我正在使用Python 3.3,64位安装,Windows操作系统,安装:WinPython.
Car*_*oba 13
你需要去
Run > Configuration per file
(或点击Ctrl+F6)并在出现的对话框中需要检查
Command line options
并写(例如)那里
1 2 3
关闭此对话框并点击后F5,您将看到您期望的输出.
注意:请记住,这些命令行选项在Spyder重新启动之间保存,作为文件运行配置的一部分,因此如果您想要更改它们,则需要Ctrl+F6再次点击.