On Sat, Feb 9, 2013 at 10:04 PM, Joshua Robinson <shooki.robin...@gmail.com> wrote: > Hi Monte-Pythons, > > x = "this is a simple : text: that has colon" > s = x.replace(string.punctuation, ""); OR > s = x.replace(string.punctuation, ""); > print x # 'this is a simple : text: that has colon' > # The colon is still in the text !!!! > > Is this a bug or am I doing something wrong ?
str.replace() replaces whole strings, not the individual characters. You probably want str.translate(): s = x.translate(string.maketrans("",""),string.punctuation) You'll then want to print s, rather than x, to see the difference. Note that it's a little different in Python 3, and you would instead use: s = x.translate(str.maketrans("","",string.punctuation)) ChrisA -- http://mail.python.org/mailman/listinfo/python-list