String Replace only if whole word?

Leonhard Vogt leonhard.vogt at
Sun Nov 19 23:38:18 CET 2006

Michael Yanowitz schrieb:
>   Yeah, I am operating this on a Python script. However, I am working off
> a requirement that the script be pre-processed and the strings replaced
> before executing the script and that if there are any remaining (not
> replaced)
> names that I don't execute the script and report that some 'mnemonics' have
> not been replaced.

If you control the source(template), you could use string formatting.

You would have to rewrite your MNEMONIC as %(MNEMONIC)s .

An exception will be raised if you miss a replacement and you are sure
you do not replace anything by accident.


More information about the Python-list mailing list