Using Python 2.7 (Anaconda Distribution): I need to parse a text file randomly terminating lines on either "\n" or "\r\n". When I use the open function with the option "rb" the script successfully interprets "\n" as a line terminator, but not "\r\n". When I use open with option "rU" (supposedly offers universal newlines support), the script breaks lines at "\r\n" but not at "\n". How can I open the file recognizing either of these different line terminators?
# recognizes "\n" but not "\r\n"
with open(infile, 'rb') as f:
reader = csv.reader(f, delimiter='|')
# recognizes "\r\n" but not "\n"
with open(infile, 'rU') as f:
reader = csv.reader(f, delimiter='|')