473,324 Members | 2,248 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,324 software developers and data experts.

Error: IndexError:list out of range

when i am executing the following code i m getting IndexError:list out of range

Expand|Select|Wrap|Line Numbers
  1. import os;
  2. import sys;
  3. file1=open(sys.argv[1],"r").readlines() # 1_train.txt
  4. file2=open(sys.argv[2],"w")
  5. for i in range(0, len(file1)):
  6.     w=file1[i].split();
  7.      if(len(w)==3):
  8.         file2.write(w[0]+"_"+w[2]+"\t"+w[1]+"\n");
  9.     else:
  10.         file2.write("\n");
Apr 23 '12 #1
1 1761
bvdet
2,851 Expert Mod 2GB
It would be helpful if you posted the complete traceback. My initial thought is you only gave it one argument. You can add print statements at strategic places to see what is taking place.

It would be more concise to iterate on the file object instead of a range. Something like:
Expand|Select|Wrap|Line Numbers
  1. file1=open(sys.argv[1],"r")
  2. for line in f:
  3.     w=line.split()
  4.     ................
Apr 23 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
4
by: Bill R via AccessMonster.com | last post by:
I get this Run-Time Error 1004 whenevery the following code runs: On Error GoTo XLSheet2 Set objXL = CreateObject("Excel.Application") With objXL Set objWkb = .Workbooks.Open(strPath) With...
11
by: Andrew Poelstra | last post by:
I hammered this out this morning to fix inconsistancies with the way my programs handle errors. The code itself is fine, in that it compiles with Richard Heathfield's gcc tags (plus -c because it...
0
by: zfraile | last post by:
I'm getting this error from the JIT compiler at runtime, but only on my boss' machine, not my development machine. I believe the error is generated from a call to an Excel object, but I can't tell...
2
by: LadyRed2 | last post by:
Hello, I am new to Excel and SQL server, so please be patient with me. I have written code with the help of others to update a table in a sql database from an excel form. The connection code...
4
by: Aaryan123 | last post by:
Function to check a number between a range in perl ========================================= Back ground: This situation has been fixed in Perl5.005. Use of .. in a for loop will iterate over...
0
by: 362315 | last post by:
I am receiving the following error: Microsoft Visual Basic Run-Time error '2147467259 (80004005)': The microsoft jet database engine cannot open the file. It is already opened exclusively by...
4
by: ielamrani | last post by:
Hi, I am getting this error when I try to export to an excel sheet. When I click on a button to export the first time it's fine, I rename the exported excel sheet and I try to export it again and I...
0
by: =?Utf-8?B?amtyYW1vczIwMDU=?= | last post by:
Hi, I had received some help earlier in the week with regards to writing a Change Macro for Excel. Now I am getting an error message and I wanted to confirm why. Below is the part of the code...
1
by: zedd | last post by:
Hi, I orignaly posted this with the error above, however I am still trying to solve it on my own, and found that some of my syntax in the query was not correct and I corrected it. But i am still...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.