By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,583 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

Writing Error in program

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.