String Replace only if whole word?

Leonhard Vogt leonhard.vogt at gmx.ch
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.
http://docs.python.org/lib/typesseq-strings.html

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.

Leonhard



More information about the Python-list mailing list