[liblouis-liblouisxml] Re: Here's the Python formatter

  • From: "Michael Whapples" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "mwhapples" for DMARC)
  • To: liblouis-liblouisxml@xxxxxxxxxxxxx
  • Date: Fri, 18 Dec 2020 07:46:19 +0000

Hello,

I left out the docstring to keep the email short and as it has little to do with the functioning of the code. Of course you can add it back in and that may be a good plan.


The "with" statements are much clearer than the associated try/except/finally blocks would be for similar reliability of closing the files. The for iteration of the lines I think is clearer than a while loop with an if and break. However its your code so do what you think you understand more.


As for joining many strings, I think using a list and then the str.join method is the way to go.


str_list = []

str_list.append("First line")

str_list.append("Second line")

long_string = "\n".join(str_list)


I believe this may be even quicker if it can be done with a list comprehension.


Michael Whapples

On 18/12/2020 03:30, John J. Boyer wrote:

Hello Michael,

Thanks for the suggestions. However, I felt the program was much easier to 
understand as I wrote it, without so many Pyth-y features.
I also wanted to make it self-contained with a doc string at the beginning.

Now I'm trying to find a way to combine many short strings which are lines from 
the input file into a long string that approximates a paragraph.
This would be passed to translateString to produce a more readable outpout. The 
hard part is to do this efficiently, without a lot of garbage collection.

John

For a description of the software, to download it and links to
project pages go to http://liblouis.org
Donate: http://liblouis.org/sponsoring

Other related posts: