<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">> How do you know how a string object is going to be treated by any<br>
> given function? Read the Fine Manual for that function.<br>
<br>
</div>So am I to understand that there is no consistency in string handling<br>
throughout the standard modules/objects/methods?<br>
<br>
Seems to make python a lot more complicated than it needs to be, but<br>
okay.<br>
<div><div></div><div class="h5"></div></div></blockquote><div><br></div><div>What it seems like you're not understanding here is that regular expressions are a special case.</div><div><br></div><div>\b means something in Python literals. It maps to a single character, \x08. It _is_ a single character.</div>
<div><br></div><div>r"\b" is two characters, a slash followed by a b. </div><div><br></div><div>Regular expressions have an _entire_ range of their own special characters that have nothing to do with Python special characters. For regular expressions, \b -- that is, a slash followed by a b -- are TWO characters (not one, like "\b" is to Python) that have special meaning.</div>
<div><br></div><div>Raw strings really exist SO you can do this. So you can do r"\b" and have the slash-followed-by-b be encoded into two characters, which the re library can then threat as a test for the blank string. Otherwise, you'd have to do "\\b" and similar a LOT when building up regular expressions...</div>
<div><br></div><div>The re library just has its own rules for how it interprets strings. Its not "no consistency". Its that regular expressions have meaning outside of Python and Python's implementation follows that general meaning (some, mostly, or to some other definition of how much). </div>
<div><br></div><div>--S</div><div><br></div></div>