Python argv taking wild card path

后端 未结 2 1323
花落未央
花落未央 2021-01-20 14:33

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?<

2条回答
  •  [愿得一人]
    2021-01-20 15:15

    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.

提交回复
热议问题