Handle spaces in argparse input

后端 未结 5 1978
逝去的感伤
逝去的感伤 2020-12-28 12:52

Using python and argparse, the user could input a file name with -d as the flag.

parser.add_argument(\"-d\", \"--dmp\", default=None)

Howev

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-28 13:18

    Simple solution: argparse considers a space filled string as a single argument if it is encapsulated by quotation marks.

    This input worked and "solved" the problem:

    -d "C:\SMTHNG\Name with spaces\MORE\file.csv"
    

    NOTICE: argument has "" around it.

提交回复
热议问题