Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38562

Re: string.replace doesn't removes ":"

Path csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Johannes Bauer <dfnsonfsduifb@gmx.de>
Newsgroups comp.lang.python
Subject Re: string.replace doesn't removes ":"
Date Sun, 10 Feb 2013 11:36:53 +0100
Organization albasani.net
Lines 28
Message-ID <kf7t7u$jmo$1@news.albasani.net> (permalink)
References <mailman.1536.1360407866.2939.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 8bit
X-Trace news.albasani.net d4cnIxwjtOw4XIH84ufmGzstvOyuqvGXAm0yY5+cfFpndbQKBwOI9V3wNGAh0Kg7KQN1/MLV+vcuxOciEPWm6Gtbh0xI4dnHxZT7CJ/l394p//024XLYZOJn0AGzDI7V
NNTP-Posting-Date Sun, 10 Feb 2013 10:36:46 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="hNWcrEDmbmN9NmskF3YbbWl3/gtUbQ8q5F9247HK/UCeQnLIW7XiUS/ghXZPTwUnUpNUMAQ/SfNJt1vrXpmRqnEolEuMoOh+tAUsq7YmOGhm1hnJ0vB9/pFl4wHaj+VI"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:10.0.11) Gecko/20121217 Thunderbird/10.0.11
In-Reply-To <mailman.1536.1360407866.2939.python-list@python.org>
Cancel-Lock sha1:x3e9rYc/fqvzzdfFAMQLu8vZMe8=
Xref csiph.com comp.lang.python:38562

Show key headers only | View raw


On 09.02.2013 12:04, Joshua Robinson 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 ?

The latter. str.replace() only replaces complete substrings, not single
character occurences of the given pattern. That is

"foo".replace("foo", "bar") == "bar"
"foofoo".replace("foo", "bar") == "barbar"
"foofoo".replace("fo", "bar") == "barobaro"
"foofoo".replace("abcdef", "bar") == "foofoo"

Regards,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1@speranza.aioe.org>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

string.replace doesn't removes ":" Joshua Robinson <shooki.robinson@gmail.com> - 2013-02-09 06:04 -0500
  Re: string.replace doesn't removes ":" Johannes Bauer <dfnsonfsduifb@gmx.de> - 2013-02-10 11:36 +0100
    Re: string.replace doesn't removes ":" vduncan80@gmail.com - 2013-02-12 07:14 -0800
  Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 20:44 -0800
    Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 21:26 -0800
    Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 21:26 -0800
      Re: string.replace doesn't removes ":" jmfauth <wxjmfauth@gmail.com> - 2013-02-12 23:10 -0800
        Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-13 08:34 -0800
          Re: string.replace doesn't removes ":" Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-13 16:55 +0000
            Re: string.replace doesn't removes ":" Walter Hurry <walterhurry@lavabit.com> - 2013-02-13 18:16 +0000
          Re: string.replace doesn't removes ":" 88888 Dihedral <dihedral88888@googlemail.com> - 2013-02-13 12:24 -0800
            Re: string.replace doesn't removes ":" jmfauth <wxjmfauth@gmail.com> - 2013-02-14 00:02 -0800
  Re: string.replace doesn't removes ":" Rick Johnson <rantingrickjohnson@gmail.com> - 2013-02-12 20:44 -0800

csiph-web