2013-08-29 38 views
7

我如何在Spyder控制台中执行Python 3.3脚本,并且有变量?如何在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: - 和(开放( “C:\测试\ myfile.py”)阅读())。我得到的错误是“ValueError:需要超过1个值才能解包,我想先提供变量=”1st“,second =”2nd“,third =”3rd“,我怎么写exec()它能够处理输入

我使用Python 3.3,64位安装,Windows操作系统,安装:?WinPython

+0

你的意思是这样的:http://stackoverflow.com/questions/89228/calling-an-external-command-in-蟒蛇/ 89243#89243 – User

回答

10

你需要去

Run > Configuration per file

(或打Ctrl+F6),在对话框中,它似乎你需要检查

Command line options

和write(例如)有

1 2 3

关闭此对话框并打到F5后,您会看到你期望的输出。

:请记住,这些命令行选项保存的Spyder之间重新启动作为文件运行配置的一部分,所以如果你想改变他们,你需要再次打Ctrl+F6

+0

如何在'Run-> Configure-> Command Line Options'中使用环境变量?我试过类似'%myEnvironmentVar%\ file.txt',但Spyder追加当前工作目录。 – user3731622

+1

对不起,您无法在该对话框中传递文件环境变量。 –

1

什么也工作是Spyder的的IPython的控制台:

In [1]: runfile('C:/yourfolder/myfile.py',args='one two three')

相关问题