Simplify merge function with read_text and write_text

This commit is contained in:
Bruno Alla 2023-01-25 23:03:07 +00:00
parent c2c10bd65a
commit 49a2433ae9
No known key found for this signature in database

View File

@ -18,13 +18,12 @@ def merge(
merged_files: Sequence[Path], merged_files: Sequence[Path],
append_linesep: bool = True, append_linesep: bool = True,
) -> None: ) -> None:
with open(output_file, "w") as output_file: merged_content = ""
for merged_file_path in merged_files: for merged_file_path in merged_files:
with open(merged_file_path) as merged_file: merged_content += merged_file_path.read_text()
merged_file_content = merged_file.read() if append_linesep:
output_file.write(merged_file_content) merged_content += os.linesep
if append_linesep: output_file.write_text(merged_content)
output_file.write(os.linesep)
def main(): def main():