How to write RTF from Python?

Bengt Richter bokr at
Sat Apr 26 20:07:21 CEST 2003

On 26 Apr 2003 16:07:34 GMT, bokr at (Bengt Richter) wrote:
>====< >========================
>import sys, os
>if len(sys.argv)<3:
>    print 'Usage: arg1 arg2'
>    raise SystemExit
>template = file('rtfexample.rtf').read().rstrip('\x00')
>places = {'redtext':sys.argv[1], 'bluetext':sys.argv[2]}
>file('rtfout.rtf','w').write(template % places)
>os.system('start write rtfout.rtf')
[1] You don't need this rstrip -- sorry. But if you isert the
whole file verbatim to make a string in a python file, like
template = """<insert here>"""
The null character will not be legal python source and has to
be edited out or changed to '\x00'. I ran into that and mistakenly
transferred the concept. A null as a final character in the string
*data* is fine, just not in the representation source text.

Bengt Richter

More information about the Python-list mailing list