I used the pandas library to manipulate the original data down to a simple 2 column csv file and rename it to a text file. The file has triple double quotes that I need replaced with single double quotes. Every line of the file is formatted as:
"""QA12345""","""Some Other Text"""
What I need is:
"QA12345","Some Other Text"
This python snippet wipes out the file after it finishes.
with fileinput.FileInput(input_file, inplace=True) as f:
next(f)
for line in f:
line.replace("""""", '"')
It doesn't work with
line.replace('"""', '"')
either.
I've also tried adjusting the input values to be '"Some Other Text"' and variations (""" and '\"') but nothing seems to work. I believe the triple quote is causing the issue, but I don't know what I have to do to.
line.replace(...)... if this is all your code, then I don't know why you expect it to do anything. Why usefileinputanyway?inplacethen I suggest not, note, it assumes you write tosys.stdout(e.g. withprintor even directly...) which is why your file is blank no matter what you do! I suggest just usingopenand manually creating the backup file. Frankly, thefileinputapproach is very weird.for line in f: print(line.replace('"""', '"'), end='')and don't forget toprint(next(f), end='')at the top.... keeping in mind, again, that printing to standard output has been implicitly replaced with your file, but this is a very weird way to go about this, IMOpd.read_csv()? I think it will do what you want.""""""is a triple double-quoted empty string.'"""'is a string with 3 double quotes.