r prefix bug ... or my lack of understanding?

Discussion in 'Python' started by Bill Sneddon, Jan 28, 2004.

  1. Bill Sneddon

    Bill Sneddon Guest

    Below is from python 2.3.3 on windows.
    I have tryed on Pythonwin and Idle and on
    a Solaris unix build 2.2.2.

    I know there are work arounds but the behavior
    seems a bit strange to me.

    >>> path = r'c:\data' #this is fine
    >>> print path

    c:\data

    >>> path = r'c:\data\'

    Traceback ( File "<interactive input>", line 1
    path = r'c:\data\'
    ^
    SyntaxError: EOL while scanning single-quoted string

    >>> path = r'c:\data\\'
    >>> print path

    c:\data\\
    Bill Sneddon, Jan 28, 2004
    #1
    1. Advertising

  2. On Wednesday 28 January 2004 2:27 pm, Bill Sneddon wrote:
    > Below is from python 2.3.3 on windows.
    > I have tryed on Pythonwin and Idle and on
    > a Solaris unix build 2.2.2.
    >
    > I know there are work arounds but the behavior
    > seems a bit strange to me.
    >
    > >>> path = r'c:\data' #this is fine
    > >>> print path

    >
    > c:\data
    >
    > >>> path = r'c:\data\'

    >
    > Traceback ( File "<interactive input>", line 1
    > path = r'c:\data\'
    > ^
    > SyntaxError: EOL while scanning single-quoted string


    Your second backslash is escaping the closing quotation mark.

    > >>> path = r'c:\data\\'
    > >>> print path

    >
    > c:\data\\


    Try this (with no "r":

    >>> print 'c:\\data\\'

    c:\data\

    James
    --
    James Henderson, Logical Progression Ltd.
    http://www.logicalprogression.net/
    http://sourceforge.net/projects/mailmanager/
    James Henderson, Jan 28, 2004
    #2
    1. Advertising

  3. On Wednesday 28 January 2004 2:27 pm, Bill Sneddon wrote:
    > Below is from python 2.3.3 on windows.
    > I have tryed on Pythonwin and Idle and on
    > a Solaris unix build 2.2.2.
    >
    > I know there are work arounds but the behavior
    > seems a bit strange to me.
    >
    > >>> path = r'c:\data' #this is fine
    > >>> print path

    >
    > c:\data
    >
    > >>> path = r'c:\data\'

    >
    > Traceback ( File "<interactive input>", line 1
    > path = r'c:\data\'
    > ^
    > SyntaxError: EOL while scanning single-quoted string
    >
    > >>> path = r'c:\data\\'
    > >>> print path

    >
    > c:\data\\


    Fuether to my last post the full details are at:

    http://www.python.org/doc/current/ref/strings.html

    >From which I quote:


    r"\" is not a valid string literal (even a raw string cannot end in an odd
    number of backslashes). Specifically, a raw string cannot end in a single
    backslash (since the backslash would escape the following quote character)

    J.
    --
    James Henderson, Logical Progression Ltd.
    http://www.logicalprogression.net/
    http://sourceforge.net/projects/mailmanager/
    James Henderson, Jan 28, 2004
    #3
  4. Bill Sneddon

    Bill Sneddon Guest

    Bill Sneddon, Jan 28, 2004
    #5
  5. Bill> Thanks I looked at faqs.org did not see it.

    That's because the Python FAQ is not posted to this list/newsgroup. It's
    only available on the web. I think faqs.org just culls FAQs from postings.

    Skip
    Skip Montanaro, Jan 28, 2004
    #6
  6. Bill Sneddon

    Terry Reedy Guest

    "Bill Sneddon" <> wrote in message
    news:bv8gtj$5ob$...
    > Below is from python 2.3.3 on windows.
    > I have tryed on Pythonwin and Idle and on
    > a Solaris unix build 2.2.2.
    >
    > I know there are work arounds but the behavior
    > seems a bit strange to me.
    >
    > >>> path = r'c:\data' #this is fine
    > >>> print path

    > c:\data
    >
    > >>> path = r'c:\data\'

    > Traceback ( File "<interactive input>", line 1
    > path = r'c:\data\'
    > ^
    > SyntaxError: EOL while scanning single-quoted string
    >
    > >>> path = r'c:\data\\'
    > >>> print path

    > c:\data\\


    Behaves as per manual.

    Note: for almost all usages, even on windows, normal Unix-style forward
    slashes works as directory terminators and avoids backslash problems
    entirely.

    path = 'C:/data/'

    Terry J. Reedy
    Terry Reedy, Jan 28, 2004
    #7
    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. =?Utf-8?B?dmJNZW50YWw=?=

    Remote debugging with asp.net (or lack thereof)

    =?Utf-8?B?dmJNZW50YWw=?=, Jan 3, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    507
    Daniel Fisher\(lennybacon\)
    Jan 4, 2005
  2. keith russell

    lack of .NET project file on web server

    keith russell, Apr 11, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    348
    =?Utf-8?B?QnJhZCBSb2JlcnRz?=
    Apr 11, 2005
  3. Tim Tyler
    Replies:
    36
    Views:
    1,437
    Darryl L. Pierce
    Dec 10, 2004
  4. Chris  Chiasson
    Replies:
    6
    Views:
    596
    Richard Tobin
    Nov 14, 2006
  5. Replies:
    4
    Views:
    87
Loading...

Share This Page