Generate config file from template using Python search and replace.
Rob Hills
rhills at medimorphosis.com.au
Sun Nov 29 21:40:29 EST 2015
A program I am writing at present does exactly this and I simply do
multiple calls to string.replace (see below)
On 30/11/15 10:31, Mr Zaug wrote:
> I seem to be heading in this direction.
>
> #!/usr/bin/env python
> import re
> from os.path import exists
>
> script, template_file = argv
> print "Opening the template file..."
>
> with open (template_file, "r") as a_string:
> data=a_string.read().replace('BRAND', 'Fluxotine')
data=data.replace('STRING_2', 'New String 2')
data=data.replace('STRING_3', 'New String 3')
> print(data)
>
> So now the challenge is to use the read().replace magic for multiple values.
It's crude, but it works well for me!
--
Rob Hills
Waikiki, Western Australia
More information about the Python-list
mailing list