string replace
Cihal Josef
josef.cihal at siemens.com
Fri Jun 30 10:12:30 EDT 2006
Hi Mechele,
In string s u want to replace string "b" or "c" to -> "x"
import re
s ="a1b2c3"
re.sub("[bc]","x",s)
Sincerely josef
Josef
-----Original Message-----
From: python-list-bounces+josef.cihal=sat-automation.com at python.org
[mailto:python-list-bounces+josef.cihal=sat-automation.com at python.org]
On Behalf Of Michele Petrazzo
Sent: Friday, June 30, 2006 4:03 PM
To: python-list at python.org
Subject: string replace
Hi,
a lot of times I need to replace more than one char into a string, so I
have to do something like
value = "test"
chars = "e"
for c in chars:
value = value.replace(c, "")
A solution could be that "replace" accept a tuple/list of chars, like
that was add into the new 2.5 for startswith.
I don't know, but can be this feature included into a future python
release?
Thanks,
Michele
--
http://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list