简体   繁体   中英

Pass an asterisk as part of a string in a command line argument into a python program?

I have a script that (in turn) calls a command line program. It would vastly simplify my life if there was a way that it could accept a command of the form

psfcheck.py -n file*.img

in a way such that within the program I could then use the term "file*.img" as a string, since there are a few times I want to pass such a string through other command line programs which need to be run on the batch of files as a group (not individually, one at a time).

Is this possible? It feels like a n00bish question, but I've been pythoning for a while and have never stumbled across this.

Put quotes around the argument:

psfcheck.py -n "file*.img"

That will prevent the shell from expanding the pattern into the list of matching files.

The shell will expand any wildcards that it finds. You can prevent this by putting them inside quotes to hide them from the shell:

psfcheck.py -n "file*.img"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM