473,769 Members | 5,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1536
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************* *************** *************@p ython.org
[mailto:py****** *************** *************** *****@python.or g
] On Behalf Of ko****@hotmail. com
Sent: Tuesday, November 20, 2007 2:03 PM
To: py*********@pyt hon.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
1781
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') >>> f.write('dan\n') >>> f.write('pat\n') >>> f.close()
8
3343
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 compiles and runs in Win2K and various Unix and Linux systems. The main program is in Fortran, calling a data writing library writen in C++. The weird thing is, it takes much longer elapse time (wall-clock time) than CPU time (e.g., 20 min vs. 2...
6
2823
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 matrix by matrix (mxm) and matrix by vector (mxv) multiplication, so obviously one of my first considerations is to ask the user if they want an mxm or mxv multiplication performed. I have written the code below (this is a working snippet of the...
4
2179
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 write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is constructed by Current Year and Current Month in my program). Is there any problems with writing into the...
2
4341
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 one having the problem. The application works fine on the test computers in my office. The test computers are all running Windows XP Service Pack 2. (Now that I wrote that I should check the version of Windows XP on the main computer.) Here is...
25
3908
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; printf("enter first string"); scanf("%s",s1); printf("enter second string");
5
6214
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 is as follows: - i am trying to write code that will take any number of text inputs (names of other text files) and put them into a file line-by-line at the users request. meaning, i want the user to be able to type the strings and enter them...
10
2339
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 file, but I want the program to exit(1) if the disk is full or some other write failure. I would like to see a C code example. Thanks in advance!
89
3861
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 record inheritance (records do have operator overloading) The idea is to write a generic integer class with derived integer classess for 8 bit, 16 bit, 32 bit, 64 bit and 64 bit emulated.
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.