I want to manipulate my text in python. I will use this text to embed as JavaScript data. I need the text in my text file to display exactly as follows. It should have the format I mention below, not only when it prints. 

I have text:

`""text""`

and I want:

`\"text\"`

```
with open('phase2.2.1.csv', 'w', newline='') as csvFile: 
    writer = csv.writer(csvFile)
    for b in batches: 
        writer.writerow([b.replace('\n', '').replace('""', '\\"')])

```

Unfortunately, the above yields 

```
\""text\""

```

Any help will be much appreciated.