on
2 mins to read.
Command Line Arguments
Command line arguments are flags given to a program/script at runtime. They contain additional information for our program so that it can execute. Not all programs have command line arguments as not all programs need them. Command line arguments allows us to give our program different input on the fly without changing the code. You can draw the analogy that a command line argument is similar to a function parameter. If you know how functions are declared and called in various programming languages, then you’ll immediately feel comfortable when you discover how to use command line arguments.
We must specify shorthand and longhand versions ( -i and –input ) where either flag could be used in the command line. This is a required argument as is noted by required=True . The help
string will give additional information in the terminal.
vars
turns the parsed command line arguments into a Python dictionary where the key to the dictionary is the name of the command line argument and the value is value of the dictionary supplied for the command line argument. Use print
to see the dictionary.
For this simple example, it will be:
You can then use those arguments in your model!
Let’s create a simple_example.py
file and see how it works!
Go do it, yourself! You can use either -n
or --name
to assign a value to the argument!
EDIT: The tf.app.flags
module is a functionality provided by Tensorflow to implement command line flags for your Tensorflow program, which Google requires internally for its developers to use. Look here, here and here for more!