Skip to content

Instantly share code, notes, and snippets.

@arnaldoleandro
Created April 3, 2023 11:36
Show Gist options
  • Save arnaldoleandro/8eecd3014a32eb946e3e52823c1e61d7 to your computer and use it in GitHub Desktop.
Save arnaldoleandro/8eecd3014a32eb946e3e52823c1e61d7 to your computer and use it in GitHub Desktop.
Buffers until size limit is reached
for line in file:
stripped_line = line.strip()
lines_buffer.append(line)
if last_element_close in stripped_line:
size += len(line.encode('utf-8'))
if size > size_limit:
output_file = os.path.join(output_dir, f"{output_file_prefix}_{file_number}.xml")
with open(output_file, 'w', encoding='utf-8') as out_file:
out_file.write(header)
write_buffered_lines(out_file, lines_buffer)
out_file.write(footer)
print(f"arquivo {file_number}: {output_dir}:{output_file_prefix}_{file_number}.xml")
file_number += 1
size = 0
lines_buffer = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment