473,381 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,381 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 1520
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Kevin T. Ryan | last post by:
Hi All - I'm not sure, but I'm wondering if this is a bug, or maybe (more likely) I'm misunderstanding something...see below: >>> f = open('testfile', 'w') >>> f.write('kevin\n') >>>...
8
by: Lu | last post by:
Hi there, I got a program to write data to a randomly accessed file (the program moves file pointer to a certain position of the file according the current "keyword" and then writes data). It...
6
by: Dawn Minnis | last post by:
Hi (running Win xp and developing using Miracle C. Running applications in windows command prompt) I'm new to the group so be gentle with me. I am currently writing a C program to perform...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
2
by: Richard Thornley | last post by:
Hello, I am working on a VB.Net application and I am getting an error ONLY on the main computer that uses the application. The main computer is on the other coast so of course it would be the...
25
by: sravishnu | last post by:
Hello, I have written a program to concatanae two strings, and should be returned to the main program. Iam enclosing the code, please give me ur critics. Thanks, main() { char s1,s2;...
5
by: grinder | last post by:
first off, i am an extreme newbie to C. i am an undergrad research assistant and i have been shifted to a project that involves building a fairly involved c program. The part that i am stuck on now...
10
by: eastcoastguyz | last post by:
(I've not done C prorgamming in such a long time, I have forgotten how to do this.) I'm writing a program, where it fopens a file with "a+", and I want to be able to continue writing to this...
89
by: Skybuck Flying | last post by:
Hello, This morning I had an idea how to write Scalable Software in general. Unfortunately with Delphi 2007 it can't be done because it does not support operating overloading for classes, or...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.