I’m having trouble splitting a text file using empty line "\n\n" delimiters.
re.split("\n", aString)
works but
re.split("\n\n", aString)
just returns the whole string.
Any ideas?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Beware the line ending conventions of different operating systems!
\r\n)\n)\r)You are probably failing because the double newline you are looking for is in a Windows-encoded text file, and will appear as
\r\n\r\n, not\n\n.The
repr()function will tell you for sure what your line endings are:Are you sure that you don’t just want to read the file line by line in the first place?