PyRTF object model

Eric Brunel eric.brunel at
Thu Sep 30 15:30:29 CEST 2010

In article <mailman.1203.1285848899.29448.python-list at>,
 Rustom Mody <rustompmody at> wrote:

> I am trying to use PyRTF.
> I gather that an RTF doc consists of a list of sections, a section
> consists of a list of paras,
> paras seem to be just text (not sure on that one)

They also include a style, not only text.

> Some questions:
> When does one end one section and start another?

You don't 'end a section. You just create a new one and append it to 
your document's sections:

my_document = PyRTF.Document()
my_section1 = PyRTF.Section()
my_section2 = PyRTF.Section()

> How does one handle lists (as in numbered, bulleted etc)?

Not sure on this one. I've had to do it, but could handle it via regular 
paragraph style properties and insert the bullets or numbers 
explicitely, so I did it just like that. For example, your can create a 
PyRTF.ParagraphPropertySet with the options left_indent to 1133 twips = 
2cm, first_line_indent to -567 twips = -1cm and set a tab at 1cm with 
the option:
Then you create a PyRTF.ParagraphStyle using this 
PyRTF.ParagraphPropertySet and pass it as the first argument when you 
create your PyRTF.Paragraph. Then, you just insert tour bullet or number 
in the paragraph explicitely, followed by a tab.
There might be a better way to do it.

BTW, as you might have noticed, the documentation for PyRTF is quite 
minimal to say the least, so the only way to figure out what can be done 
is by reading the PyRTF source codeŠ

 -Eric -

More information about the Python-list mailing list