file open fails.

Scott David Daniels Scott.Daniels at Acm.Org
Tue Mar 24 18:04:25 EDT 2009


Atul. wrote:
> title = 'C:\Thesis\refined_title.txt'
> file = open(title)
> I get the following error from Python.
>     file = open(title)
> IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\Thesis
> \refined_title.txt'

> Now, I can not understand the problem here ...
Repesat to yourself 1e4 tmes: "I shall not put windows file
names in quotes w/o using 'r' (as in raw files).  Either
always use forward slashes, or get used to typing:
       title = r'C:\Thesis\refined_title.txt'

In your case, '\r' is a return (a single character), not two
characters long. I think its sad that 'C:\Thesis' doesn't cause
an error because there is no such character as '\T', but I am
probably excessively pedantic.

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list