From: Justin Park on
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,



From: Ian Kelly on
On Fri, Jun 18, 2010 at 2:26 PM, Justin Park <hp6(a)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.
From: MRAB on
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.

From: D'Arcy J.M. Cain on
On Fri, 18 Jun 2010 15:26:14 -0500
Justin Park <hp6(a)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. "

Exact test script and traceback please. I would like to see what line
gives you the error. Are you trying to read the file that you opened
in append mode?

By the way, your email address doesn't work. I get a "relay access
denied" message.

--
D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
From: D'Arcy J.M. Cain on
On Fri, 18 Jun 2010 17:22:00 -0400
"D'Arcy J.M. Cain" <darcy(a)druid.net> wrote:
> By the way, your email address doesn't work. I get a "relay access
> denied" message.

Ignore that. It was a local problem that I fixed before sending but
forgot to remove this paragraph.

--
D'Arcy J.M. Cain <darcy(a)druid.net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.