How can I strip first and last double quotes?

后端 未结 13 1288
抹茶落季
抹茶落季 2020-12-02 10:14

I want to strip double quotes from:

string = \'\"\" \" \" \"\"\\\\1\" \" \"\" \"\"\'

to obtain:

string = \'\" \" \" \"\"\\\         


        
13条回答
  •  日久生厌
    2020-12-02 10:52

    Almost done. Quoting from http://docs.python.org/library/stdtypes.html?highlight=strip#str.strip

    The chars argument is a string specifying the set of characters to be removed.

    [...]

    The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped:

    So the argument is not a regexp.

    >>> string = '"" " " ""\\1" " "" ""'
    >>> string.strip('"')
    ' " " ""\\1" " "" '
    >>> 
    

    Note, that this is not exactly what you requested, because it eats multiple quotes from both end of the string!

提交回复
热议问题