How do I send arguments to a function by using windows command prompt?

You can play with this ...

# test Python command line arguments

import sys

if (len(sys.argv) >= 2):
    # skip sys.argv[0]
    commandline_args = sys.argv[1:] 
    print( commandline_args ) 
        
raw_input("Press Enter to go on ...")  # wait

"""my output for args  1 2 3  -->
['1', '2', '3']
"""

How do I call the program from the command line?

How do I call the program from the command line?

Type your python command (*if you haven't set it up you'll need to use the full pathname to python.exe or pythonw.exe), then the name of your script, then the command line arguments... here's an example:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>
C:\>edit cmd_args.py

C:\>C:\Python26\python.exe cmd_args.py these are command line args


C:\>

Note: The cmd_args.py simply contained the following:

import sys
print sys.argv

In my environment I've set the "python" command to point to "C:\Python26\python.exe", that way when I'm in the cmd line I can just type "python <script_name> [args]"... it's much faster.

Thanks for the help. Problem solved. :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.