Confusing textwrap parameters, and request for RE help

Steve Smith Steve.A.Dore at outlook.com
Sun Mar 29 00:21:04 EDT 2020


I am having the same issue. I can either get the text to wrap, which makes all the text wrap, or I can get the text to ignore independent '/n' characters, so that all the blank space is removed. I'd like to set up my code, so that only 1 blank space is remaining (I'll settle for none at this point), an the text wraps up to 100 chars or so out per line. Does anyone have any thoughts on the attached code? And what I'm not doing correctly?


#import statements
import textwrap
import requests
from bs4 import BeautifulSoup

#class extension of textwrapper
class DocumentWrapper(textwrap.TextWrapper):

    def wrap(self, text):
        split_text = text.split('\n')
        lines = [line for para in split_text for line in textwrap.TextWrapper.wrap(self, para)]
        return lines

#import statement of text.
page = requests.get("http://classics.mit.edu/Aristotle/rhetoric.mb.txt")
soup = BeautifulSoup(page.text, "html.parser")

#instantiation of extension of textwrap.wrap.
d = DocumentWrapper(width=110,initial_indent='',fix_sentence_endings=True )
new_string = d.fill(page.text)

#set up an optional variable, even attempted applying BOTH the extended method and the original method to the issue... nothing has worked.
#new_string_2 = textwrap.wrap(new_string,90)

#with loop with JUST the class extension of textwrapper.
with open("Art_of_Rhetoric.txt", "w") as f:
    f.writelines(new_string)

#with loop with JUST the standard textwrapper.text method applied to it.
with open("Art_of_Rhetoric2.txt", "w") as f:
    f.writelines(textwrap.wrap(page.text,90))


-----Original Message-----
From: Python-list <python-list-bounces+steve.a.dore=outlook.com at python.org> On Behalf Of Dan Sommers
Sent: Friday, March 27, 2020 3:51 PM
To: python-list at python.org
Subject: Re: Confusing textwrap parameters, and request for RE help

On Fri, 27 Mar 2020 15:46:54 -0600
Michael Torrie <torriem at gmail.com> wrote:

> On 3/27/20 3:28 PM, Dan Stromberg wrote:

> > Back when I was a kid, and wordprocessors were exemplified by 
> > WordStar, I heard about a study the conclusion of which was that 
> > aligned right edges were harder to read - that it was better to 
> > align on the left and leave the right ragged.

I remember WordStar, and its text editor cousin WordMaster.

> > But one study doesn't establish truth.

> I've read poorly-typeset, self-published books that were really hard 
> to read due to the way the full justification worked out.  Not sure if 
> that's just due to the poor typesetting job (a word processor probably 
> did it), or the font, or what.  There must be some tricks that 
> publishers use to both justify and keep the text looking good and 
> readable ...

Ask Donald Knuth why he invented TeX, and why math is enclosed in literal $ (U+0024) characters.  ;-)

Also, there are word processors and there are word processors.  From an aesthetics perspective, TeX has been producing beautiful printed pages (and pairs and sequences of pages) for decades, Word still didn't the last time I looked (maybe 8 or 10 years ago?), and there are dozens or more in between.

> ... At one point in the print world, the majority of what I read is 
> fully justified, yet still quite readable.  Even now I think most 
> published books I've seen recently are fully justified. These days, 
> seems like more and more is ragged-right, such as magazines, which is 
> probably due to the prevalence of digital media where it's probably 
> easier to generate and easier to read on small screens.

If content producers did their job well, a 2540 pixel per inch printed page, a desktop 72 or 96 pixel per inch display screen, and a handheld
320 pixel per inch screen would all be optimized separately (through one sort of style sheet mechanism or another).  But these days, they spend more time and money on ads and SEO than typesetting.

Dan

--
“Atoms are not things.” – Werner Heisenberg Dan Sommers, http://www.tombstonezero.net/dan
--
https://mail.python.org/mailman/listinfo/python-list


More information about the Python-list mailing list