I can run a script on the command line with an argument either as the bare "script.py arg1" or I can run it as "python script.py arg1". Both work until I use argparse for command line parameters.
The bare script does not recognize arg1:
Directories.py
usage: directories.py [-h] [-f FILE] directory
directories.py: error: the following arguments are required: directory
"python directories.py arg1" does work with argparse.
WHY?
Can I fix that bare script? Can I make the bare "directories.py arg1" work?
(I don't really understand why under Windows the bare script executes. I assume there is a python association.)
Here is the argparse part:
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Get tree from single dir or dir list from file")
parser.add_argument("directory", type=str, help="Get single directory")
# Adding argument
parser.add_argument("-f", "--file", help = "Get directories from a file")
# Read arguments from command line
args = parser.parse_args()
main(args)
.pyfiles. To check, first open a command prompt (not Powershell) and runassoc .py. It should print.py=and something after the=. Runftype whateverwasaftertheequalssign, substituting whatever was after the equals sign. Then show us everything those two commands printed.print(sys.argv)diagnostic line at the beginning of your main.