Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

how to execute Python 3.3 script in Spyder console with variables?

how can I execute Python 3.3 script in Spyder console, and that has variables?

My sample code (C:/test/myfile.py) is

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)

I have tried exec(open("C:estmyfile.py").read()) - and the error I get is "ValueError: need more than 1 value to unpack. I want to supply the variables first = "1st", second = "2nd", third = "3rd". How can I write the exec() so that it can handle the inputs?

I'm using Python 3.3, 64-bit installation, Windows OS, installation: WinPython.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You need to go

Run > Configuration per file

(or hit Ctrl+F6) and in the dialog that it appears you need to check

Command line options

and write (for example) there

1 2 3

After closing this dialog and hitting F5, you'll see the output you are expecting.

Note: Please remember that these command line options are saved between Spyder restarts as part of the file run config, so if you want to change them, you need to hit Ctrl+F6 again.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...