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


Groups > comp.lang.python > #61266

Re: Is It Bug?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'skip:\\ 20': 0.07; 'string': 0.09; 'python': 0.11; "'\\\\'": 0.16; 'backslash': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'wrote:': 0.18; 'working.': 0.19; '>>>': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'interpret': 0.24; 'replace': 0.24; 'asking': 0.27; 'header:In-Reply-To:1': 0.27; 'code': 0.31; '>>>>': 0.31; 'actual': 0.34; 'maybe': 0.34; 'but': 0.35; 'method': 0.36; 'subject:?': 0.36; 'so,': 0.37; 'to:addr:python- list': 0.38; 'to:addr:python.org': 0.39; "you're": 0.61; 'header :Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'clearer': 0.84; 'reply-to:addr:python.org': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=C6LQl2/+ c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=OJn0C7AadrgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=myyjZcGpYoJ_R08ndjcA:9 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Sun, 08 Dec 2013 01:12:44 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Is It Bug?
References <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com>
In-Reply-To <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3715.1386465166.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386465166 news.xs4all.nl 2902 [2001:888:2000:d::a6]:57358
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61266

Show key headers only | View raw


On 08/12/2013 00:59, Mahan Marwat wrote:
> Why this is not working.
>
>>>> 'Hello, \\\\World'.replace('\\', '\\')
>
> To me, Python will interpret '\\\\' to '\\'. And the replace method
> will replace '\\' with '\'. So, the result will be 'Hello, \World'.
> But it's give me 'Hello, \\\\World'.
>
> The result I want form the code is 'Hello, \World'.
>
The original string contains 2 actual backslashes:

>>> print('Hello, \\\\World')
Hello, \\World

Both the search and replacement strings contain 1 backslash:

>>> print('\\')
\

You're asking it to replace every backslash with a backslash!

If you want to replace 2 consecutive backslashed with a single
backslash:

 >>> 'Hello, \\\\World'.replace('\\\\', '\\')
'Hello, \\World'

Maybe it's clearer if you print it:

 >>> print('Hello, \\\\World'.replace('\\\\', '\\'))
Hello, \World

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


Thread

Is It Bug? Mahan Marwat <mahanmarwat@gmail.com> - 2013-12-07 16:59 -0800
  Re: Is It Bug? Chris Angelico <rosuav@gmail.com> - 2013-12-08 12:05 +1100
    Re: Is It Bug? Roy Smith <roy@panix.com> - 2013-12-07 20:22 -0500
      Re: Is It Bug? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-12-08 11:01 +0100
      Re: Is It Bug? Chris Angelico <rosuav@gmail.com> - 2013-12-08 21:04 +1100
      Re: Is It Bug? Chris Angelico <rosuav@gmail.com> - 2013-12-08 21:26 +1100
  Re: Is It Bug? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-08 01:06 +0000
  Re: Is It Bug? MRAB <python@mrabarnett.plus.com> - 2013-12-08 01:12 +0000
  Re: Is It Bug? Tim Roberts <timr@probo.com> - 2013-12-07 22:53 -0800
  Re: Is It Bug? Peter Otten <__peter__@web.de> - 2013-12-08 11:43 +0100

csiph-web