Text Manipulation in Python

Thomas Fuchs tgfuchs at my-deja.com
Wed Nov 10 16:11:40 CET 1999


In article <VA.00000012.055a8702 at ops.corpex.com>,
  edward at corpex.com wrote:
> I am completely new to Python.
>
> We want to use it to alter specific lines in template files, typically
> something like changing:-
>
> Variable = 1234
>
> to
>
> Variable = Company Name
>
If you can specify the format of the template file, use Python syntax.
For example:

# file: mytemplate.py
t = '''\
-----------------------
Variable = %(company)s
-----------------------
'''

# file: mymain.py
import mytemplate
company = 'CoCo'
f = open('myoutput', 'w')
f.write(mytemplate.t % locals())
f.close()



Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list