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


Groups > comp.lang.python > #61260 > unrolled thread

Is It Bug?

Started byMahan Marwat <mahanmarwat@gmail.com>
First post2013-12-07 16:58 -0800
Last post2013-12-07 23:39 -0700
Articles 4 — 4 participants

Back to article view | Back to comp.lang.python


Contents

  Is It Bug? Mahan Marwat <mahanmarwat@gmail.com> - 2013-12-07 16:58 -0800
    Re: Is It Bug? Iuri <iurisilvio@gmail.com> - 2013-12-07 23:04 -0200
    Re: Is It Bug? rusi <rustompmody@gmail.com> - 2013-12-07 21:48 -0800
    Re: Is It Bug? Joshua Gardner <mellowcellofellow@gmail.com> - 2013-12-07 23:39 -0700

#61260 — Is It Bug?

FromMahan Marwat <mahanmarwat@gmail.com>
Date2013-12-07 16:58 -0800
SubjectIs It Bug?
Message-ID<5865401e-aef8-4dd2-927c-52d2b7ca3ed8@googlegroups.com>
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'.

[toc] | [next] | [standalone]


#61263

FromIuri <iurisilvio@gmail.com>
Date2013-12-07 23:04 -0200
Message-ID<mailman.3712.1386464680.18130.python-list@python.org>
In reply to#61260

[Multipart message — attachments visible in raw view] — view raw

This way, it will replace '\' with '\', so nothing change.

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


On Sat, Dec 7, 2013 at 10:58 PM, Mahan Marwat <mahanmarwat@gmail.com> 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'.
> --
> https://mail.python.org/mailman/listinfo/python-list
>

[toc] | [prev] | [next] | [standalone]


#61272

Fromrusi <rustompmody@gmail.com>
Date2013-12-07 21:48 -0800
Message-ID<598b3c82-37b8-47bf-a5dc-fcfab266d34f@googlegroups.com>
In reply to#61260
On Sunday, December 8, 2013 6:28:24 AM UTC+5:30, 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'.

I am mystified by this question.
Yes '\\' may be one slash or two or something else more exotic.
But whatever it is (and its not a syntax error like with '\') it is something.
So how can ....replace(something,something)....  be anything other
than a no-op?

[toc] | [prev] | [next] | [standalone]


#61273

FromJoshua Gardner <mellowcellofellow@gmail.com>
Date2013-12-07 23:39 -0700
Message-ID<l8147t$k81$2@speranza.aioe.org>
In reply to#61260
If I'm having to deal with incessant backslashes in a string I'll often
use the r'\' (raw string literal) syntax. Simplifies things quite a bit.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web