Store variable name in another variable

7stud bbxx789_05ss at yahoo.com
Tue May 1 09:43:40 EDT 2007


On May 1, 6:43 am, loial <a... at loial.co.uk> wrote:
> OK, I have it working with dictionaries.
>
> However I have another scenerio :
>
> I am reading a file containing records like the following :
>
> <IMPOSITION_DOCUMENT>
> <WFBAN_PAGE>
> <WFBAN_START_DETAILS name=\""MYVARIABLE"\">
> ..
> ..
>
> I need to substitute MYVARIABLE with the current value of MYVARIABLE
> in my python script and write the file out again.
>
> The file may contain many more lines and many substitution values on
> any line
>
> Assuming that MYVARIABLE is currently set to JOHN then the output
> would be
>
> <IMPOSITION_DOCUMENT>
> <WFBAN_PAGE>
> <WFBAN_START_DETAILS name="JOHN">
>
> Can this be done in Python?


s = "hello world, goodbye world"
result = s.replace("world", "moon")
print result




More information about the Python-list mailing list