Am Mittwoch, 11. März 2015 um 17:57:29, schrieb José Matos <jama...@lyx.org>
> On Wednesday 11 March 2015 16:28:30 Kornel Benko wrote:
> > This is probably trivial, but I could not see the error in dos2unix.py.
> > ...
> > cd /usr/BUILD/BuildLyxGitQt5/po && /usr/bin/python3 
> > /usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py 
> > /usr/BUILD/BuildLyxGitQt5/po/lyx2.2.cat_tmp.pot
> > Traceback (most recent call last):
> >   File "/usr/src/lyx/lyx-git/development/cmake/po/dos2unix.py", line 11, in 
> > <module>
> >     outstr = instr.replace( "\r\n", "\n" ).replace( "\r", "\n" )
> > TypeError: expected bytes, bytearray or buffer compatible object
> > ...
> > Does 'infile.read()' return something different in python3?
> 
> Yes, depending on the flag passed in the read option either bytes or strings.
> 
> $ ipython3
> In [1]: type(open( "examples.txt", "rb").read())
> Out[1]: bytes
> 
> In [2]: type(open( "examples.txt", "r").read())
> Out[2]: str
> 
> $ ipython2
> In [1]: type(open( "examples.txt", "rb").read())
> Out[1]: str
> 
> In [2]: type(open( "examples.txt", "r").read())
> Out[2]: str
> 
> So in python3 you get what you ask for. An array of bytes for a binary file.
> 
> At the same time I notice that there is a logical error in the script, in the 
> line
> 
> if len(outstr) == len(instr):
>   continue
> 
> That does not make sense, because if the file has mac end of lines (\r) the 
> files will be different but the number of characters will be the same.
> 
> A better test would be
> 
> if outstr == insrt: continue
> 

Thank you José. If I understood correctly, the opposite of 'open(..,"r")' 
should be 'open(..,"w")'.
(See development/cmake/po/dos2unix.py:15)
With also this extra change the script worked too.

        Kornel

        Kornel

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to