[Tutor] searching for newlines does not work!

2010-10-23 Thread win...@interchange.ubc.ca
This is driving me batty!

In the interactive window, I can use string.replace on newlines for some
strings and not for others.

Here is what work for newlines:

b...@bill-laptop:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> test=r"a \n b \n c \n"
>>> test.replace(r"\n","***")
'a *** b *** c ***'

Yay! So far, so good. But now I put in a string with newlines, test2, using
the triple quote method :

>>> test2="""
... a
... b
... c
... """
>>> test2.replace(r"\n","***")
'\na\nb\nc\n'
>>> test2
'\na\nb\nc\n'

Boo! It does not work. So there here is my question: Why does test work but
test2 does not? (And: Why me?)

Thanks for any suggestions,

Bill
___
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] searching for newlines does not work!

2010-10-23 Thread win...@interchange.ubc.ca
(Hope this reply makes it back to the Tutor list; I didn't see how the list
would know this is a reply... I'm trying a reply-all)

This is where I say Doh! and Thanks!

I realize now where my fuzzy-headedness come from. I generally use re
expressions. If these were re search strings, the raw would be necessary.
But they aren't re expressions; they are string expressions. So r is as in
wrong, wrong, wrong!

So, I was stuck in re mode, unable to shift out to string mode. (Doh!)

Thank you for steering this lost lamb back into the python fold

Best,

Bill


On Sat, Oct 23, 2010 at 3:47 PM, Alan Gauld wrote:

>
> "Adam Bark"  wrote
>
>
___
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor