1

Here is the simple code

import sys
print  (sys.argv[1])

I am working on passing argument to PYTHON from PHP For that first I want to make sure Python taking argument successfully. For that purpose i am running that simple two line code and I am getting Error

C:\wamp3\www\v3.0>argument.py hello
Traceback (most recent call last):
File "C:\wamp3\www\v3.0\argument.py", line 2, in <module>
print  (sys.argv[1])
IndexError: list index out of range

Can anyone suggest some solution. I have gone through previous posted questions but nothing seems to work for me.

Garry
  • 342
  • 5
  • 18
  • I am running it from terminal like "argument.py hello" – Garry Jul 24 '18 at 00:51
  • 1
    This might interest you: https://stackoverflow.com/questions/4765085/using-command-line-arguments-in-python-understanding-sys-argv – Austin Jul 24 '18 at 00:53
  • 1
    Looks like windows doesn't pass the argument properly. What happens for `python argument.py hello` – John La Rooy Jul 24 '18 at 00:54
  • 1
    guess you have to call `python argument.py hello` – rafaelc Jul 24 '18 at 00:54
  • thank you guys >>python argument.py hello solved the problem – Garry Jul 24 '18 at 00:56
  • IIRC, this can happen if you had an old Python, from before the `py.exe` launcher existed, and then installed a newer one. Instead of your scripts running with `py`, which knows how to preserve argv, they get run with `python`, which doesn't. Or something like that. But, even if I'm right, I don't remember how to get out of that state if you get into it. – abarnert Jul 24 '18 at 01:06
  • This was a completely different problem from the one originally used as a duplicate target... but still, I think, a duplicate. – Karl Knechtel Aug 09 '22 at 08:39

0 Answers0