Ad

IOError: [Errno 22] Invalid Mode ('r') Or Filename: 'c:\\Python27\test.txt'

- 1 answer

What is wrong with the following:

test_file=open('c:\\Python27\test.txt','r')
Ad

Answer

\t is a tab character. Use a raw string instead:

test_file=open(r'c:\Python27\test.txt','r')

or double the slashes:

test_file=open('c:\\Python27\\test.txt','r')

or use forward slashes instead:

test_file=open('c:/Python27/test.txt','r')
Ad
source: stackoverflow.com
Ad