0

I am struggling with passing 2 arguments in spyder using the command line. I have used the run-->configuration per file and in the command line options put JPEGtoPNG.py/Poxedex/new/. The JPEGtoPNG is the python file and the arguments to be passed are poxedex and new.

Dilemma: When i run print(sys.argv[0]) it prints:

runcell(0, '/Users/chideraokafor/JPEGtoPNG.py')

which i understand is the default. However when i run print(sys.argv[1]) it prints:

IndexError: list index out of range.

I have tried everything but still, it's not passing the two arguments, and I really don't want to use pycharm.

Tugay
  • 2,057
  • 5
  • 17
  • 32
  • Please see my answer in the question I referenced above. Also, that doesn't work for cells, only when you run the entire file. – Carlos Cordoba Jan 17 '22 at 23:38

1 Answers1

0

If Poxedex and new are command line arguments for a script, JPEGtoPNG.py, execution should be:

python JPEGtoPNG.py Poxedex new

Not / separated.

Note that the error you get is because you are not passing command line arguments and as such sys.argv is a list of length one (that one being the script name) and indexing starts at 0 in Python so accessing the second element via sys.argv[1] is indeed out of range.

Since Spyder provides a Python console and the options you are passing via the menu are intended as that - options and not arguments - you might find it easier to run the script(s) from the command line, for example using VSCode.

Even if you don't want to use VSCode, you can just open a terminal window and invoke the script from there. Just check your environment variables to ensure Python is on your system (or user) path.

Anil
  • 1,097
  • 7
  • 20