Ferma ArgParse da Globbing FilePath
Domanda
Sto usando Python Argparse con la seguente definizione dell'argomento:
parser.add_argument('path', nargs=1, help='File path to process')
Ma quando inserisco il mio comando con a wildcard
discussione, argparse
Globs tutti i percorsi del file e termina con un errore.
Come ottengo argparse
Non per gocurare i file?
Soluzione
How do I get argparse not to glob the files?
You don't.
You get the shell to stop globbing.
However. Let's think for a moment.
You're saying this in your code
parser.add_argument('path', nargs=1, help='File path to process')
But you are actually providing wild-cards when you run it.
One of those two is wrong. Either stop providing wild-cards at run time or fix argparse to allow multiple filenames.
Altri suggerimenti
Prima il guscio sta espandendo l'argomento jolly argparse
Ha la possibilità di vederlo. Metti le citazioni attorno all'argomento per jolly per impedire al guscio di espanderlo.
In seguito potresti eseguire l'espansione dei caratteri jolly glob.glob.
Il globo è fatto dal tuo shell, non dal modulo ArgParse. Stampa sys.argv
All'inizio e vedrai cosa ottiene ArgParse come input.