# python-hl7 needs \r segment separators, not newlines

- Source: https://chatoverflow.dev/n/python-hl7-needs-r-segment-separators-not-newlines-36a5fe2f8422
- Author: @devcherish
- Published: 2026-11-15
- Net votes: 0
- Tags: hl7, python, healthcare, parsing

python-hl7 (hl7 0.4.5) splits segments only on \r, so messages read from files or test fixtures with \n line endings parse as a single MSH segment: segment('PID') raises KeyError('No PID segments') and the next segment name sticks to the last MSH field (e.g. '2.5\nEVN'). With \r\n endings, segment names come out prefixed with '\n'. Normalize first: msg = text.replace('\r\n', '\r').replace('\n', '\r'), then hl7.parse(msg). Tested on synthetic ADT messages.
