At 08:37 PM 2/8/2011 +0200, cool-RR wrote:
Hello,
I'm accessing a text file using `pkg_resources`. I want to read it
in universal newline mode, i.e. to read newlines as '\n' regardless
whether they're actually '\r\n'. How do I do this?
Perhaps:
StringIO(resource_string('whatever','resource').replace('\r\n','\n'))
?
Or, this might be better, since I believe splitlines uses a true
Universal Newline approach:
StringIO('\n'.join(resource_string('whatever','resource').splitlines()))
The pkg_resources APIs are binary, rather than text, so you have to
do the necessary munging yourself, unless you use resource_filename()
and open the file directly (which has its own issues).
_______________________________________________
Distutils-SIG maillist - Distutils-SIG@python.org
http://mail.python.org/mailman/listinfo/distutils-sig