raw strings and \

Steven D'Aprano steve at REMOVETHIScyber.com.au
Sun Mar 5 12:05:04 EST 2006


On Sun, 05 Mar 2006 08:27:31 -0800, plahey wrote:

> Hi Duncan,
> 
> thanks for the reply.  I figured that this was a technical problem
> associated with the parser.
> 
> This one is going on my Python gotchas list.  It is really silly from
> an end user perspective to have \ not special in raw strings _except_
> if it is the last character.

I don't deny that this is a gotcha, but you misunderstand the purpose of
raw strings. They weren't designed so that Windows users could enter
pathnames with backslashes. Raw strings are designed to enter regular
expressions, and for regular expressions, not being able to end a string
with a backslash is not a bug but a feature.

See http://www.ferg.org/projects/python_gotchas.html#contents_item_2

(and try not to choke on the oh-so-saccharine-sweet cutesy introduction.
Red Ridinghood indeed *wink*)


-- 
Steven.




More information about the Python-list mailing list