maybe someone will give a short example. what should be spelled out in the python script so that it would accept the parameter "from outside".
I read that as if def, I tried it did not work out.

    3 answers 3

    sys.argv example

    sys.argv documentation

    sys.argv is a list in python that contains the command-line arguments passed to the script.

    With the len (sys.argv) function you can count the number of arguments.

    If you’re gonna be sys.argv.

    To use sys.argv, you need to import the sys module.

      The standard python library has a module argparse.

      Example:

      import argparse parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer for the accumulator') parser.add_argument('--sum', dest='accumulate', action='store_const', const=sum, default=max, help='sum the integers (default: find the max)') args = parser.parse_args() print(args.accumulate(args.integers)) 

      If the example above is saved as prog.py and run, we get:

       $ python prog.py -h usage: prog.py [-h] [--sum] N [N ...] Process some integers. positional arguments: N an integer for the accumulator optional arguments: -h, --help show this help message and exit --sum sum the integers (default: find the max) 

        I think it's a good idea to use the getopt method.

        Here is a small, brief example (everything is simplified as much as possible, but the idea is clear):

         import sys import getopt def usage(): print 'Help!!!' try: options, args = getopt.getopt(sys.argv[1:], 'd:o:h', ['debug=', 'option=', 'help']) except getopt.GetoptError: usage() sys.exit(2) for opt, value in options: if opt in ('-h', '--help'): usage() sys.exit(0) elif opt in ('-d', '--debug'): debug_flag = value print 'debug flag: ', debug_flag elif opt in ('-o', '--option'): option = value print 'option: ', option 
        • getopt is a mockery in the world of python. Never use it - Andrio Skur