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

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

My sample code (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) 

I tried exec (open ("C: \ test \ myfile.py"). Read ()), and the error I get is "ValueError: requires more than 1 value to unpack. I want to provide the variables first =" 1st " , second = "2nd", third = "3rd". How can I write exec () so that it can handle inputs?

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

+10
python spyder
source share
2 answers

You need to go

Run > Configuration per file

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

Command line options

and write (for example) there

1 2 3

After closing this dialog and pressing F5 you will see the expected result.

Note. Remember that these command-line options are saved between Spyder restarts as part of the file launch configuration, so if you want to change them, you need to press Ctrl+F6 again.

+13
source share

What also works is the Spyder IPython console:

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

+2
source share

All Articles