Convert single-quoted string to double-quoted string

后端 未结 5 1828
无人及你
无人及你 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:09

    In my case I needed to print list in json format. This worked for me:

    f'''"inputs" : {str(vec).replace("'", '"')},\n'''
    

    Output:

    "inputs" : ["Input_Vector0_0_0", "Input_Vector0_0_1"],
    

    Before without replace:

    f'"inputs" : {vec},\n'
    
    "inputs" : ['Input_Vector0_0_0', 'Input_Vector0_0_1'],
    

提交回复
热议问题