Pattern-match & Replace - help required

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Dec 19 12:09:47 CET 2012


On Wed, 19 Dec 2012 03:01:32 -0800, AT wrote:

> I just wanted to change taxpayer.enc_name in stmnt to
> decrypt(taxpayer.enc_name)
> 
> hope it clarifies?

Maybe. Does this help?

lunch = "Bread, ham, cheese and tomato."
# replace ham with spam
offset = lunch.find('ham')
if offset != -1:
    lunch = lunch[:offset] + 'spam' + lunch[offset + len('ham'):]
print(lunch)




-- 
Steven



More information about the Python-list mailing list