How to write RTF from Python?
Bengt Richter
bokr at oz.net
Sat Apr 26 14:07:21 EDT 2003
On 26 Apr 2003 16:07:34 GMT, bokr at oz.net (Bengt Richter) wrote:
[...]
>====< rtfexample.py >========================
>import sys, os
>if len(sys.argv)<3:
> print 'Usage: rtfexample.py arg1 arg2'
> raise SystemExit
>template = file('rtfexample.rtf').read().rstrip('\x00')
^^^^^^^^^^^^^^^-[1]
>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.
Regards,
Bengt Richter
More information about the Python-list
mailing list