1

I have a string like the below:

"{
  ""station-id"": ""FMAT2"", 
  ""lon"": ""-97.37055556"", 
  ""value"": ""8.66"", 
  ""lat"": ""32.80805556"", 
  ""data-type"": ""PCIRR"", 
  ""time"": ""210606"", 
  ""date"": ""170417""
}"

I need to replace all "" with ". I used the below code for that, but the thing is that " works and makes ) green. So would you help me resolve this problem.

line = line.replace("",")

TNX

4
  • 2
    Multiline strings need to be triple quoted. Also, you need to quote your quotes in replace. Use single quotes. line = line.replace('""', '"') Commented Jun 26, 2017 at 15:43
  • line = line.replace('""','"'). Notice i surrounded the double quote strings with single quote strings Commented Jun 26, 2017 at 15:43
  • How did you get a string like that? You should be storing that as a dict or JSON or similar! Commented Jun 26, 2017 at 15:44
  • I try to send a JSON line with only one quot as follows: {"station-id": "FMAT2", "lon": "-97.37055556", "value": "8.58", "lat": "32.80805556", "data-type": "PCIRR", "time": "195350", "date": "170417"}. But when I try to post it to an API endpoint, it changes to double quot!! see: stackoverflow.com/questions/44730210/… Commented Jun 26, 2017 at 15:47

2 Answers 2

4

Try

line = line.replace('""', '"') 
Sign up to request clarification or add additional context in comments.

Comments

1

I know the question has already been answered but just to clarify @erip comment. you should place your quotes like this next time.

"""
{
  "station-id": "FMAT2", 
  "lon": "-97.37055556", 
  "value": "8.66", 
  "lat": "32.80805556", 
  "data-type": "PCIRR", 
  "time": "210606", 
  "date": "170417"
}
"""

4 Comments

How does this answer OP's question ?
@MooingRawr see +erip comment
@Tushortz That only works if the OP has access to the data. It could have come from an external source where the OP can't change the content
@Wondercricket posted it before I saw OP comment that he was posting to API endpoint

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.