4
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by mahela007
Featured Replies
  • 2

    Maybe a little example will help ... [code=python]import sys args = sys.argv print(args) print( "Source file: %s" % args[0] ) # use any of these arguments in your code print( "Argument one: %s" % args[1] ) print( "Argument two: %s" % args[2] ) """ my output after saving this code … Read More

  • It allows your program to launch other programs and communicate with them. Read More

0

That's exactly where I checked. I don't understand what the documentation says..
More specifically I don't understand this
"sys.argv¶

The list of command line arguments passed to a Python script. argv[0] is the script name (it is operating system dependent whether this is a full pathname or not). If the command was executed using the -c command line option to the interpreter, argv[0] is set to the string '-c'. If no script name was passed to the Python interpreter, argv[0] is the empty string."

2

Maybe a little example will help ...

import sys

args = sys.argv

print(args)
print( "Source  file: %s" % args[0] )
# use any of these arguments in your code
print( "Argument one: %s" % args[1] )
print( "Argument two: %s" % args[2] )


"""
my output after saving this code as sysargs1.py and 
entering a few arguments on the command line -->
['D:/Python25/Bull/sysargs1.py', 'myarg1', 'myarg2']
Source  file: D:/Python25/Bull/sysargs1.py
Argument one: myarg1
Argument two: myarg2
"""
Comments
A short ,clear post. .I deal for forums
0

So for the last two to have values, is it compulsory for the program to be run via command line?

0

You can run it with module subprocess as well

import subprocess
child = subprocess.Popen("sysargs1.py myarg1 myrag2", shell=True)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.