-1

Does anyone know why I can't send arguments when executing a script? I have installed python 3.8.1, Windows 10 x64. I have an environment variable (the folder where my scripts are). I can execute the scripts like this:

nameScript.py

and it works but if I put

nameScript.py 1

and in this script I use that '1', sys.argv[1] give an error: Index out of bounds.

If I execute the script like:

python D/path_to_script/nameScript.py 1

it works.

khelwood
  • 55,782
  • 14
  • 81
  • 108

2 Answers2

1

your editor configuration is different than default command prompt.May be that is not reading your path and other things.

when executing like

nameScript.py 1

it understand that nameScript.py is a program and 1 is argument. hence

sys.argv[0] = 1
sys.argv[1] = Error
Notepad
  • 1,659
  • 1
  • 12
  • 14
0

sys.argv is filled with command line arguments. The first one sys.argv[0] is the script name, then sys.argv[1] is the first argument. Like this:

python myscript.py arg1 arg2 

Then sys.argv[0] is 'myscript.py' sys.argv[1] is 'arg1' sys.argv[2] is 'arg2'

I think you need to create an enviroment variable that points to your python/bin folder instead your project/script folder.

franvergara66
  • 10,524
  • 20
  • 59
  • 101