We need kind of look-ahead functionality here: the last line should not be followed by the normal separator, only a '\n'. I dont see a better solution by using context managers here, but maybe i didnt understand your thought.