I run into a problem in opening a file in Python

Ian Kelly ian.g.kelly at gmail.com
Fri Jun 18 17:17:29 EDT 2010


On Fri, Jun 18, 2010 at 2:26 PM, Justin Park <hp6 at rice.edu> wrote:
> But when I change the file access mode into "a",
> it returns an error message of "IOError: [Errno 9] Bad file descriptor. "
>
> What have I done wrong?

"a" is for appending only.  You can't read from a file opened in that
mode.  If you want to both read and append, you should use mode 'r+'
or 'a+', depending on whether you want the stream initially positioned
at the beginning or end of the file.



More information about the Python-list mailing list