I run into a problem in opening a file in Python
MRAB
python at mrabarnett.plus.com
Fri Jun 18 17:20:11 EDT 2010
Justin Park wrote:
> The problem is simple.
> I have 50taxa2HGT_1.txt in the current directory,
> and I can open it using any text editor (which indicates there actually
> is.)
>
> And I can read it in Python using
>>>> fd=open("./50taxa2HGT_1.txt", "r")
> , and it actually got opened, because I can do
>>>> for line in fd:
> ... print line
>
> 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?
>
> Thanks in advance,
>
Mode "a" opens the file for appending, which means that you can't read
from it, only write to it.
For Python 2.6.5 on Windows XP Pro I get:
IOError: File not open for reading
which is more helpful.
More information about the Python-list
mailing list