Warum nicht anerkannt argParse arg1 in bloß "my_script .py arg1" vs "python my_script.py arg1"Python

Python-Programme
Anonymous
 Warum nicht anerkannt argParse arg1 in bloß "my_script .py arg1" vs "python my_script.py arg1"

Post by Anonymous »

Ich kann ein Skript in der Befehlszeile mit einem Argument entweder als "script.py arg1" ausführen oder ich kann es als "python script.py arg1" ausführen. Beide arbeiten, bis ich ArgParse für Befehlszeilenparameter verwende.

Code: Select all

Directories.py
usage: directories.py [-h] [-f FILE] directory
directories.py: error: the following arguments are required: directory
< /code>
"Python -Verzeichnisse.py arg1" funktioniert mit argParse. < /p>
Warum? Kann ich die bloße "Verzeichnisse.py arg1" funktionieren?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)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post