Python argparse argument with quotes

后端 未结 2 1086
一向
一向 2021-01-12 02:04

Is there any way I can tell argparse to not eat quotation marks?

For example, When I give an argument with quotes, argparse only takes what\'s inside of the quotes a

2条回答
  •  没有蜡笔的小新
    2021-01-12 02:43

    Command line is parsed into argument vector by python process itself. Depending on how python is built, that would be done by some sort of run-time library. For Windows build, that would be most likely MS Visual C++ runtime library. More details about how it parses command line can be found in Visual C++ documentation: Parsing C++ command-Line arguments.

    In particular:

    • A string surrounded by double quotation marks ("string") is interpreted as a single argument, regardless of white space contained within. A quoted string can be embedded in an argument.

    • A double quotation mark preceded by a backslash (\") is interpreted as a literal double quotation mark character (").

    If you want to see unprocessed command line, on Windows you can do this:

    import win32api
    print(win32api.GetCommandLine())
    

提交回复
热议问题