Convert single-quoted string to double-quoted string

后端 未结 5 1858
无人及你
无人及你 2020-12-25 12:32

I want to check whether the given string is single- or double-quoted. If it is single quote I want to convert it to be double quote, else it has to be same double quote.

5条回答
  •  生来不讨喜
    2020-12-25 13:01

    Sounds like you are working with JSON. I would just make sure it is always a double quoted like this:

    doubleQString = "{0}".format('my normal string')
    with open('sampledict.json','w') as f:
        json.dump(doubleQString ,f)
    

    Notice I'm using dump, not dumps.

    Sampledict.json will look like this:

    "my normal string"
    

提交回复
热议问题