So I have the following code, that puts a delimiter of ~||~ after every semicolon, or 500 characters. This is working, but is removing the semicolons when it finds them. I have looked on here, and found an answer, but I can't get this to work in my code.
chunk_len = 100
split_char = ';'
delim = ("~||~")
d = ";"
f = open(filename, "r")
text = f.read()
f.close()
lines = text.split(';')
for lines_idx, line in enumerate(lines):
length = len(line)
if length > chunk_len:
chunks = [line[idx:idx+chunk_len]for idx in range(0,length,chunk_len)]
lines[lines_idx] = delim.join(chunks)
new_text = delim.join(lines)
f = open(outputfile, 'w')
f.write(new_text)
f.close()
I found this solution on here, but I couldn't find a way to incorporate it into my code. Sorry for the duplicated question.
d = ">"
for line in all_lines:
s = [e+d for e in line.split(d) if e != ""]