python – IOError: [Errno 22] invalid mode (r) or filename: c:\Python27test.txt
python – IOError: [Errno 22] invalid mode (r) or filename: c:\Python27test.txt
t
is a tab character. Use a raw string instead:
test_file=open(rc:Python27test.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)
always use r to get a raw string when you want to avoid escape.
test_file=open(rc:Python27test.txt,r)
python – IOError: [Errno 22] invalid mode (r) or filename: c:\Python27test.txt
is an escape character in Python.
t
gets interpreted as a tab. If you need character in a string, you have to use
\
.
Your code should be:
test_file=open(c:\Python27\test.txt,r)
Related posts:
- How to transform an XML file using XSLT in Python?
- Python Logging (function name, file name, line number) using a single file.
- python – Writing Unicode text to a text file?
- How can I extract the folder path from file path in Python?
- string – Is there a native templating system for plain text files in Python?
- python: cant open file get-pip.py error 2] no such file or directory.
- Python, Pandas : write content of DataFrame into text File.
- python – What can lead to IOError: [Errno 9] Bad file descriptor during os.system()?
- Python : Compare two csv files and print out differences.
- How to save a list as a .csv file with python with new lines?