Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use argv with Spyder

Tags:

python

spyder

I'm running the code below in Spyder. I have typed it in a py file and simply hit the run button.

When I try to run it I get the error:

ValueError: need more than 1 value to unpack

As shown here you are meant to give the inputs for the argv variable before running the program but I don't know how to do this is spyder?

http://learnpythonthehardway.org/book/ex13.html

from sys import argv  script, first, second, third = argv  print "The script is called:", script print "The first variable is:", first print "The second variable is:", second print "Your third variable is:", third 
like image 835
Bazman Avatar asked Oct 31 '14 16:10

Bazman


People also ask

How do you run commands on Spyder?

To run a script in Spyder IDE, there are two options: use the command line option, use runfile in IPython.

How do you run a line by line on Spyder on a Mac?

The key to run the current line by itself is F9 . The shortcut ctrl+F10 is used if you are in debugging mode.

How do I schedule a Python script in Spyder?

To schedule a Python script with Task scheduler, create an action and add the path to your Python executable file, add the path to the script in the “Start in” box and add the name of the Python file ase an argument. Then, create a trigger to schedule the execution of your script.


2 Answers

To pass argv to a script in Spyder, you need to go the menu entry

Run > Configuration per file

or press the Ctrl+F6 key, then look for the option called

Command line options

on the dialog that appears after that, and finally enter the command line arguments you want to pass to the script, which in this case could be

one two three

like image 148
Carlos Cordoba Avatar answered Sep 20 '22 13:09

Carlos Cordoba


In addition to configuring in the Run->Configure as explained in other answers, you can use "runfile" directly from the console.

Run the following:

   runfile('ex13.py', args='first second third') 
like image 23
mors Avatar answered Sep 19 '22 13:09

mors