Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6234397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:28:43+00:00 2026-05-24T10:28:43+00:00

I an running this code: #!/usr/bin/python coding=utf8 # test.py = to demo fault def

  • 0

I an running this code:

#!/usr/bin/python      coding=utf8
#  test.py = to demo fault
def loadFile(path):
    f = open(path,'r')
    text = f.read()
    return text
if __name__ == '__main__':
    path = 'D:\work\Kindle\srcs\test1.html'
    document = loadFile(path)
    print len(document)

It gives me a trackback

D:\work\Kindle\Tests>python.exe test.py
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    document = loadFile(path)
  File "test.py", line 5, in loadFile
    f = open(path,'r')
IOError: [Errno 22] invalid mode ('r') or filename: 'D:\\work\\Kindle\\srcs\test1.html'

D:\work\Kindle\Tests>

If I change the path line to

path = 'D:\work\Kindle\srcs\\test1.html'

(note the double \\) it all works fine.

Why? Either the separator is ‘\’ or it is not, not a mix?

System. Windows 7, 64bit,
Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)] on win32

Checked – and all the backslashes appear correctly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:28:44+00:00Added an answer on May 24, 2026 at 10:28 am

    The backslash is an escape character when the next character combination would result in a special meaning. Take the following examples:

    >>> '\r'
    '\r'
    >>> '\n'
    '\n'
    >>> '\b'
    '\x08'
    >>> '\c'
    '\\c'
    >>>
    

    r, n, and b all have special meanings when preceded by a backslash. The same is true for t, which would produce a tab. You either need to A. Double all your backslashes, for consistency, because '\\' will produce a backslash, or, B, use raw strings: r'c:\path\to\my\file.txt'. The preceding r will prompt the interpreter not to evaluate back slashes as escape sequences, preventing the \t from appearing as a tab.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running this code parsesendnotes.pl #!/usr/bin/perl use strict; use warnings; use Device::SerialPort; use Time::HiRes qw(usleep);
The code #!/usr/bin/env python import MySQLdb print Content-Type: text/html print print <html><head><title>Books</title></head> print <body>
I'm running this simple code: import threading, time class reqthread(threading.Thread): def run(self): for i
Running FxCop on my code, I get this warning: Microsoft.Maintainability : 'FooBar.ctor is coupled
Similar to this question , after running the following code the browser dialog does
Following the directions at this question , I have some code running to extract
I have the following python modules. Sorry if the code is ugly. This is
I'm running Python 2.5, so this question may not apply to Python 3. When
I'm running this code: $db = new Mongo(mongodb://user:pw@flame.mongohq.com:27081/dbname); $collection = $db->foobar; $collection->insert($content); I'm trying
#!/usr/bin/perl use strict; use warnings; sub paragraph { open my $file, <, dict.txt or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.