File call error message (double backslash)

Discussion in 'Python' started by Fred, Mar 8, 2005.

  1. Fred

    Fred Guest

    Hi
    I am writing on an application, that is supposed to read a file into a
    single string:
    My program though, when I run it, gives me an error, that the called
    file is non existent
    'C:\ \Documents and Settings\ \Fred\ \My Documents\ \School\ \Bio'
    Is it normal that python adds the space and extra backslash? Because
    if I print the path of the called file before the open command, it
    normally prints it with only one backslash.
    Is there any possiblity of surpressing this?
    I am using Python 2.3.5 with Pywin built 163 on Windows.
    Thanks for all help
     
    Fred, Mar 8, 2005
    #1
    1. Advertising

  2. Fred

    M.E.Farmer Guest

    Hello Fred,
    Backslashes are used as an escape and not just in Python ( consider
    '\r\n' )
    To use a backslash you must escape it with two of them like this: \\
    'c:\\windows\\dir'
    or you can use a raw string:
    r"c:\windows\dir"
    or you can use forward slashes. Yes that works ;)
    "c:/windows/dir"

    Windows uses '\' as a path sep but it also understands '/'.
    *nix uses '/' as a path sep.

    hth,
    M.E.Farmer
     
    M.E.Farmer, Mar 9, 2005
    #2
    1. Advertising

  3. Fred

    John Machin Guest

    Fred wrote:
    > Hi
    > I am writing on an application, that is supposed to read a file into

    a
    > single string:
    > My program though, when I run it, gives me an error, that the called
    > file is non existent
    > 'C:\ \Documents and Settings\ \Fred\ \My Documents\ \School\ \Bio'
    > Is it normal that python adds the space and extra backslash? Because
    > if I print the path of the called file before the open command, it
    > normally prints it with only one backslash.


    The space between the \ \ is NOT normal. Please post the exact (copy
    and past!) text of the trace-back and error message.
     
    John Machin, Mar 9, 2005
    #3
    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. Sydex
    Replies:
    12
    Views:
    6,658
    Victor Bazarov
    Feb 17, 2005
  2. Harry George
    Replies:
    5
    Views:
    788
    Gerrit Holl
    Jan 19, 2004
  3. Vincent Texier
    Replies:
    3
    Views:
    2,417
    Vincent Texier
    Jul 1, 2004
  4. Stef Mientki

    Double backslash in filepaths ?

    Stef Mientki, Apr 14, 2007, in forum: Python
    Replies:
    3
    Views:
    795
    Stef Mientki
    Apr 14, 2007
  5. Peter Tosh
    Replies:
    7
    Views:
    787
    Peter Tosh
    Jun 12, 2009
Loading...

Share This Page