On Tuesday 10 November 2009 08:54:13 Guenter Milde wrote: I am trying to reply since yesterday morning so better to send some snippets than not to reply at all. :-)
I like the patch and I will try to give some of the reasons why the original code was as it was. > Some explanations: > > * trim_eol() is replaced with the standard string method splitlines() This code comes from lyx2lyx, at the time that this code was created lyx was supposed to work with python 1.5 where trim was not available. > * "input" is a built-in Python function, so the variable/argument is > renamed to "source". this has been fixed in lyx2lyx > * read(): instead of looping over the lines, the file is read in one block > and splitted into a list of lines. lyx files can be a lot bigger than layout files. :-) > (trim_bom() could also be run on the return value of file.read() before > splitting, this is a matter of taste. I went for processing just the > first line.) > > * write(): instead of looping, the list of lines is joined and written > in one step (faster, "pythonic" way of doing it). > There are further (not so important) optimizations/cleanups possible. > These are left as an exercise for the reader ;-) Some of this could be applied to lyx2lyx, could you take a look, please? > Günter FWIW all the changes make sense. As a last remark it would like to say that it would be interesting to put some of this in a general library to deal with all our file formats and to upgrade/downgrade our preferences, bind, layout, ui... Running out of time... :-) -- José Abílio