[reportlab-users] Bit of help with wrapping text in a paragraph

John Precedo reportlab-users@reportlab.com
Mon, 10 Feb 2003 21:06:41 -0000


Bill W said:
> I knew my random typing would get me in trouble eventually  ;-)


Buried away in reportlab.lib is a random text generator. This is pretty
handy when it comes to having randomised text for testing paragraphs and
suchlike.

This is what the docstring for it says:

############################################################################
###
#   generates so-called 'Greek Text' for use in filling documents.
############################################################################
###
"""
This module exposes a function randomText() which generates paragraphs.
These can be used when testing out document templates and stylesheets.
A number of 'themes' are provided - please contribute more!
We need some real Greek text too.

There are currently six themes provided:
    STARTUP (words suitable for a business plan - or not as the case may
be),
    COMPUTERS (names of programming languages and operating systems etc),
    BLAH (variations on the word 'blah'),
    BUZZWORD (buzzword bingo),
    STARTREK (Star Trek),
    PRINTING (print-related terms)
    PYTHON (snippets and quotes from Monty Python)

EXAMPLE USAGE:
    from reportlab.lib import randomtext
    print randomtext.randomText(randomtext.PYTHON, 10)

    This prints a random number of random sentences (up to a limit
    of ten) using the theme 'PYTHON'.

"""

Trying this out in practice does stuff like this:

C:\code\reportlab>python
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

>>> from reportlab.lib import randomtext

>>> print randomtext.randomText(randomtext.PYTHON, 3)
Blah blah blah blah blah blah blah Stop right there! You're a very silly man
and
 I'm not going to interview you. blah blah blah blah blah blah blah blah
Amongst
 our weaponry are such diverse elements as: fear, surprise, ruthless
efficiency,
 an almost fanatical devotion to the Pope, and nice red uniforms - Oh damn!
blah
 blah blah blah You're a very silly man and I'm not going to interview you.
Spam
 sausage Spam Spam Spam bacon Spam tomato and Spam blah.

>>> print randomtext.randomText(randomtext.BUZZWORD, 3)
Blah blah solutioning solutioning blah blah blah blah blah Total Quality
Management
blah blah blah downsize. Blah blah backward-compatible blah real estate blah
blah
networking blah blah blah blah. Blah blah blah blah blah blah blah blah blah
blah
peel the onion blah blah blah blah blah blah quarterly blah blah blah.
>>>

Mildly amusing sometimes, but more importantly it linebreaks better than
'dslkfjlkjfkjsalfjasldfjlasjdflajsfljaslfjasldfjalsjfklaksdjf' ;)

--
John Precedo  (johnp@reportlab.com)    Developer
Reportlab Europe Ltd  (http://www.reportlab.com)