Substitution with Hash Values

David Bolen db3l at fitlinxx.com
Mon Apr 22 15:39:36 EDT 2002


holger krekel <pyth at devel.trillke.net> writes:

> But is it true that you 'never' use them somewhere else? 
> I would think that one would like to use 'r' whenever you don't 
> want the escape-sequence-string-interpretation which is not really
> restricted to regexp-strings. 

Exactly.

I use them all the time when I need a \ in my strings for some reason
or another.  Regex's are probably the most obvious cross-platform
case, but I think the next most likely case in our code is when
encoding Windows file paths (so this is less common for Unix
environments).  Sometimes you want a native looking path for display
purposes (otherwise in many cases you can just use forward slashes
even under Windows), or sometimes (as with some UNC paths) you really
need the backslashes.

> I have noticed that e.g. the docstring of the module os.py uses
> r'...'

I've done it in docstrings too when I used examples or other text that
included characters that regular strings would interpret.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list