[Tutor] Template long text substitution
Stefan Lesicnik
stefan at lsd.co.za
Mon Aug 24 23:14:16 CEST 2009
Hi Guys,
I am trying to do the following, and im not sure how to deal with a blob of
text.
I have the following file i am using as a template
%%NAME%%
%%NUMBER%%
%%REPORT%%
and i have a corresponding file with values
name="bob"
number="123"
report="report is long
and spans multiple
lines. It also is already in the exact format
i want to replace the above template var %%REPORT%% with"
The report part is obviously the problem. My code so far reads line by line
and splits on the = and reads the values into a dict.
file = open('test','r')
data = {}
for line in file:
line = line.strip()
line = line.split('=')
data[line[0]] = line[1]
My intention is then to replace the %%NAME%% with data['name'] etc.
If it makes a difference, the report= will be generated by another program
and given to me in the exact format i need to substitute it into %%REPORT%%.
(or i can put it in that file).
I hope this makes sense, thanks in advance - i really do appreciate it :)
Stefan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090824/cd613890/attachment-0001.htm>
More information about the Tutor
mailing list