472,110 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,110 software developers and data experts.

Writing Error in program

I have a code that writes to 2 seperate files. I keep getting a "list
index out of range" error. The strange part is that when checking the
files that I'm writing too, the script has already iterated through
and finished writing, yet the error stated implies that it hasn't? So
how can it be, that my script has written to the files, yet the error
is stating that it hasn't made it through the script? I'll have 15
files that I have written to and the script will bog out at number
10? Is python doing something I'm not seeing? I printed everything
that was written on the shell and it shows that it went through the
script, so how can it still say there are a few files left to iterate
through?
Nov 20 '07 #1
3 1445
There could be any number of issues in your code that could cause that
problem.
Can you post some of the code in question?
-----Original Message-----
From: py*****************************************@python .org
[mailto:py***************************************** @python.org
] On Behalf Of ko****@hotmail.com
Sent: Tuesday, November 20, 2007 2:03 PM
To: py*********@python.org
Subject: Writing Error in program

I have a code that writes to 2 seperate files. I keep getting a "list
index out of range" error. The strange part is that when checking the
files that I'm writing too, the script has already iterated through
and finished writing, yet the error stated implies that it hasn't? So
how can it be, that my script has written to the files, yet the error
is stating that it hasn't made it through the script? I'll have 15
files that I have written to and the script will bog out at number
10? Is python doing something I'm not seeing? I printed everything
that was written on the shell and it shows that it went through the
script, so how can it still say there are a few files left to iterate
through?
--
http://mail.python.org/mailman/listinfo/python-list
Nov 20 '07 #2
On Nov 20, 3:02 pm, kou...@hotmail.com wrote:
I have a code that writes to 2 seperate files. I keep getting a "list
index out of range" error. The strange part is that when checking the
files that I'm writing too, the script has already iterated through
and finished writing, yet the error stated implies that it hasn't? So
how can it be, that my script has written to the files, yet the error
is stating that it hasn't made it through the script? I'll have 15
files that I have written to and the script will bog out at number
10? Is python doing something I'm not seeing? I printed everything
that was written on the shell and it shows that it went through the
script, so how can it still say there are a few files left to iterate
through?
Could you post some of the code and the traceback? It would be
especially good to see your list and make sure you're iterating
through it correctly. Do you open the file in the loop, write to it
and close it?

How can it write to 15 files and then quit at number 10? That
statement seems to contradict itself.

More details for the group would be great. Thanks!

Mike
Nov 20 '07 #3
On Tue, Nov 20, 2007 at 01:02:38PM -0800, ko****@hotmail.com wrote regarding Writing Error in program:
>
I have a code that writes to 2 seperate files. I keep getting a "list
index out of range" error. The strange part is that when checking the
files that I'm writing too, the script has already iterated through
and finished writing, yet the error stated implies that it hasn't? So
how can it be, that my script has written to the files, yet the error
is stating that it hasn't made it through the script? I'll have 15
files that I have written to and the script will bog out at number
10? Is python doing something I'm not seeing? I printed everything
that was written on the shell and it shows that it went through the
script, so how can it still say there are a few files left to iterate
through?
As others have mentioned, posting code would be very helpful. Also, what you say doesn't sound right. "List index out of range" does not mean there are a few files left to iterate through. It means that you have a list somewhere and you are trying to access an index beyond the last list item.

So say you have the following list:

l=['a','b','c']

and you try to access each item in it with the following loop:

for x in range(4):
print l[x]

You will get the following output.

a
b
c
Traceback (most recent call last):
File "<stdin>", line 2, in ?
IndexError: list index out of range

in other words it will print l[0], l[1], and l[2], but then when it tries to print l[3], it will raise an IndexError, because there is no l[3]. This does not mean it still has files to process. More likely, it means it has overshot the files it does have to process, but more likely still it has nothing to do with file access. We can't help you diagnose that without a code sample, though.

Cheers,
Cliff

Nov 20 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Kevin T. Ryan | last post: by
8 posts views Thread by Lu | last post: by
5 posts views Thread by grinder | last post: by
89 posts views Thread by Skybuck Flying | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.