On Tue, Jan 18 2011, Harish S wrote:

> On Tue, Jan 18, 2011 at 5:39 PM, Harish S <[email protected]> wrote:
>
>>
>> Hello,
>>   I am new to python. I have a doubt.
>>   How will I open a file which is placed in a different directory (other
>> than the current working directory)?
>>   Wen I try to open the file using the command "file =
>> open("d:\desktop\....")", it says :
>>
>>   IOError: [Errno 22] invalid mode <'r'> or filename: '......'
>>
>> Can you please specify the reason for this?

[...]

On windows, the backslash used to separate directories can be
misinterpreted as escape sequences. So you'd best do

   f = open(r"d:\Desktop\MyFile.txt")

The r before the " indicates that the string is "raw" and that things
like \n, \t etc. should not be interpreted as special characters
(newline, tab etc.)

Also, what is "......."? Is that your filename? Is that a legal filename
under Windows?

-- 
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers

Reply via email to