
Hi, I saw a pice of code about “command line argument”:
import sys print(sys.argv) ['demo.py', 'one', 'two', 'three']
on this page: https://docs.python.org/3/tutorial/stdlib.html#command-line-arguments It shows how to get a list of parameters and looks like it's in interactive mode. But I can't do the same thing in interactive mode, sys.argv is always return empty list, unless I put these code in a script and execute it. Does this mean this sample code not too clear? Regards -- ----------- Runbing

Hey Runbing, the text beforehand states "For instance the following output results from running python demo.py one two three at the command line" which to me means the output should be shown without the leading >>>'s. On Thu, Jul 14, 2022, at 6:44 PM, Runbing wrote:
Hi,
I saw a pice of code about “command line argument”:
import sys print(sys.argv) ['demo.py', 'one', 'two', 'three']
on this page:
https://docs.python.org/3/tutorial/stdlib.html#command-line-arguments
It shows how to get a list of parameters and looks like it's in interactive mode.
But I can't do the same thing in interactive mode, sys.argv is always return empty list, unless I put these code in a script and execute it.
Does this mean this sample code not too clear?
Regards -- ----------- Runbing _______________________________________________ docs mailing list -- docs@python.org To unsubscribe send an email to docs-leave@python.org https://mail.python.org/mailman3/lists/docs.python.org/ Member address: cmdr@supakeen.com
participants (2)
-
Runbing
-
Simon de Vlieger