readline() with arbitrary end of lines

Javier Bezos see.below at no.spam.es
Mon Sep 11 14:43:06 CEST 2000


Manuel Gutierrez Algaba <thor at localhost.localdomain> wrote:

> On Sun, Javier Bezos <see.below at no.spam.es> wrote:
> >Hello,
> >
> >I'm using MacPython 1.5.2c1 to read several files with
> >the help of readline(). However, the files to be read can
> >have either Mac or Unix end of lines and it seems that only
> >Mac end of lines are recognized; changing linesep has no
> >effect at all.

> You can do this:
> 
> import string
> b=[]
> for i in a:
>       for j in string.split(a,"\015"):
>               if j[-1]=="\012":
>                       b.append(j[-1])
>               else:
>                       b.append(j)
> 
> 
> In b there's all the lines, independtly of the OS. 

Gracias, Manolo (and for the private email, too). Sadly,
the files to be read are PostScript ones -- very large, you
know (even > 2M). btw, PostScript recognizes the three
variants, as well -- a serious failure of Python, indeed.
> 
> You can wrap it into a function.

I think that I can define a class with a buffer, so that I
can analyze the contents and then extract the lines. What a
complication for such a simple task!

Chao
___________________________________________________________
Javier Bezos              | TeX y tipografia
jbezos at wanadoo dot es  | http://perso.wanadoo.es/jbezos/



More information about the Python-list mailing list