Re: Best Practice Question

Discussion in 'Python' started by python.list@tim.thechases.com, Feb 5, 2013.

  1. Guest

    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
     
    , Feb 5, 2013
    #1
    1. Advertising

  2. On Tuesday, February 5, 2013 10:17:54 AM UTC-5, wrote:
    > 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?
     
    Anthony Correia, Feb 5, 2013
    #2
    1. Advertising

  3. On Tuesday, February 5, 2013 10:17:54 AM UTC-5, wrote:
    > 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?
     
    Anthony Correia, Feb 5, 2013
    #3
  4. On Tue, Feb 5, 2013 at 11:40 AM, Anthony Correia <>wrote:

    > On Tuesday, February 5, 2013 10:17:54 AM UTC-5, :
    > > 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
     
    Joel Goldstick, Feb 5, 2013
    #4
  5. Dave Angel Guest

    On 02/05/2013 11:53 AM, Joel Goldstick wrote:
    > On Tue, Feb 5, 2013 at 11:40 AM, Anthony Correia <>wrote:
    >
    >> On Tuesday, February 5, 2013 10:17:54 AM UTC-5, :
    >>> 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'
    >>>>

    >


    Worse than that, the code as posted by the OP used string concatenation
    before calling os.path.join(), and the latter method does nothing at
    all, when presented with a single string.



    --
    DaveA
     
    Dave Angel, Feb 5, 2013
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan Ax
    Replies:
    0
    Views:
    625
    Bryan Ax
    Jun 26, 2003
  2. Prince

    Best Practice - Question

    Prince, Jan 17, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    347
    Kevin Spencer
    Jan 19, 2004
  3. Josh

    Best Practice Question

    Josh, Jun 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    341
    Mike Labosh
    Jun 23, 2005
  4. Jason MacKenzie

    Best Practice Question

    Jason MacKenzie, Nov 21, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    397
    Jason Kester
    Nov 22, 2005
  5. oldyork90
    Replies:
    1
    Views:
    177
    Jeremy J Starcher
    Sep 10, 2008
Loading...

Share This Page