Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python argv taking wild card path

I run my script with doc1/*.png as first argument, but it gets converted to doc1/image1.png.

How can I let Python see the exact argument?

img_list = []
print sys.argv[1]
x = sys.argv[1]
img_list = [img for img in glob.glob(x)]
like image 970
Prince Patel Avatar asked Aug 19 '26 20:08

Prince Patel


1 Answers

On most linux shells (bash, sh, fish,...), the asterisk is handled by the shell. The fact that the * is converted to a list of files is already done at the shell level.

If you write:

python file.py doc/*.png

The shell itself will translate doc/*.png into "doc/1.png" "doc/2.png" (so a list of .png files it finds in the doc directory.

You should use quotes to pass the asterisk, like:

python file.py 'doc/*.png'

The standard Windows shell does not do wildcards for file names.

like image 126
Willem Van Onsem Avatar answered Aug 21 '26 10:08

Willem Van Onsem