Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/abvar/fix_quotes.py
1128 views
1
import shutil
2
import re
3
4
def fix_quotes(filename,tmpfile):
5
sublist_finder = re.compile(r"(\[[^\]]*\])")
6
with open(filename) as infile:
7
with open(tmpfile,'w') as fixedfile:
8
for L in infile.readlines():
9
parts = sublist_finder.split(L[1:-2].replace(" ",""))
10
#parts[5] = '["' + parts[5][1:-1].replace(',','","') + '"]'
11
#parts[11] = '[[' + parts[11][1:-1] + ',1]]'
12
parts[13] = '["' + parts[13][1:-1].replace(',','","') + '"]'
13
fixedfile.write('[' + ''.join(parts) + ']\n')
14
shutil.move(tmpfile,filename)
15
16