file open fails.

MRAB google at mrabarnett.plus.com
Tue Mar 24 18:14:27 EDT 2009


Atul. wrote:
> Hi I am using IDLE on Windows Vista and I have a small code.
> 
> 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 I have all the permissions
> set for the folder, file as well. I can not understand why would it
> happen. Is it known on Windows Vista or am I missing something really
> simple and stupid? Please help.
> 
Backslash has a special meaning in string literals. Use a raw string
instead or double the backslashes:

     title = r'C:\Thesis\refined_title.txt'

or:

     title = 'C:\\Thesis\\refined_title.txt'




More information about the Python-list mailing list