[Distutils] Reading in Universal Newline mode with pkg_resources
cool-RR
cool-rr at cool-rr.com
Wed Feb 9 21:08:06 CET 2011
On Wed, Feb 9, 2011 at 7:52 PM, P.J. Eby <pje at telecommunity.com> wrote:
> 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()))
>
Do you think that source_string.replace('\r', '') would work?
> 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).
>
Maybe an option for text-mode reading should be added?
Ram.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20110209/a2b35303/attachment.html>
More information about the Distutils-SIG
mailing list