Basic task: converted a URL request into text, and dumped it to a text file (almost a usable CSV).
Goal: A clean CSV. On multiple lines, I'm trying to replace multiple (different) characters:
brackets, tildes (~), extra commas at the end of each line.
I cannot find any relatively simple-to-follow examples to accomplish this. Looking for something that can cycle line by line and replace.
PLEASE NOTE: I expect this file to be large over time, so not memory friendly.
Below is the code that created the file:
import urllib.request
with urllib.request.urlopen(URL1) as response:
data = response.read()
decoded_data = data.decode(encoding='UTF-8')
str_data = str(decoded_data)
saveFile = open("test.txt",'w')
saveFile.write(str_data)
saveFile.close()
Here is a simplified sample from the file, the first line has the field names, 2nd and 3rd lines represent records.
[["F1","F2","F3","F4","F5","F6"],
["string11","string12","string13","s~ring14","string15","string16"],
["string21","string22","s~ring23","string24","string25","string26"]]