Best Practice Question

Joel Goldstick joel.goldstick at gmail.com
Tue Feb 5 17:53:24 CET 2013


On Tue, Feb 5, 2013 at 11:40 AM, Anthony Correia <akcorreia at gmail.com>wrote:

> On Tuesday, February 5, 2013 10:17:54 AM UTC-5, pytho... at tim.thechases.comwrote:
> > On Tue, 5 Feb 2013 15:32:32 +0100 (CET), Jean-Michel Pichavant wrote:
> >
> > > By the way, did someone ever notice that r'\' fails ? I'm sure
> >
> > > there's a reason for that... (python 2.5) Anyone knows ?
> >
> > >
> >
> > > r'\'
> >
> > > SyntaxError: EOL while scanning single-quoted string
> >
> >
> >
> > I hit this all the time with Vim's path-completion (":help
> >
> > i_CTRL-X_CTRL-F") on Win32 which puts a trailing "\" on
> >
> > directory-names.  I just need to remember to remove it, a task made
> >
> > easier because the syntax highlighting correctly shows how Python
> >
> > interprets it (i.e., the string is still continued).
> >
> >
> >
> > -tkc
>
> Sorry about that I hit the touchpad on my laptop by mistake.  Beside the
> using  single '\' vs a double '\\' does that look ok?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

according to the docs for os.path.join, you don't need the backslash stuff
at all.  Python knows the correct separator for your os and inserts it
accordingling:
I'm on linux:

>>> import os
>>> p = os.path.join('bob', 'bill')
>>> p
'bob/bill'
>>>


-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130205/db7b7718/attachment.html>


More information about the Python-list mailing list