[BangPypers] Doubt regarding python file management
Harish S
harishisnow at gmail.com
Tue Jan 18 14:03:40 CET 2011
Hello,
The correction worked for me. Thanks a lot for your response.
Regards,
Harish
On Tue, Jan 18, 2011 at 6:02 PM, Noufal Ibrahim <noufal at gmail.com> wrote:
> On Tue, Jan 18 2011, Harish S wrote:
>
> > On Tue, Jan 18, 2011 at 5:39 PM, Harish S <harishisnow at gmail.com> 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
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>
More information about the BangPypers
mailing list