From e416dbbf4117a655aa490a4bf5c7e672a7b925ee Mon Sep 17 00:00:00 2001 From: Benjamin Kahn Date: Mon, 5 Jan 2026 09:45:03 -0500 Subject: [PATCH] Allow newlines as a segment separator --- x12/parser/parse.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/x12/parser/parse.py b/x12/parser/parse.py index 660c728..6ac179a 100644 --- a/x12/parser/parse.py +++ b/x12/parser/parse.py @@ -12,7 +12,7 @@ def parse(file_path: str, x12: Schema, context: Context = Context("~", "*", ":") content = "" try: - with open(file_path, "r", encoding="utf-8") as file: + with open(file_path, "rt", encoding="utf-8") as file: content = file.read() except FileNotFoundError: print(f"unable to find {file_path}") @@ -22,7 +22,10 @@ def parse(file_path: str, x12: Schema, context: Context = Context("~", "*", ":") raise # Remove the line-breaks and than split by segment separator to get the lines. - lines = content.replace("\r", "").replace("\n", "").split(context.segment_separator) + if context.segment_separator != "\n": + lines = content.replace("\r", "").replace("\n", "").split(context.segment_separator) + else: + lines = content.replace("\r", "").split(context.segment_separator) root = Loop(x12, context) head = root