Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8968901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:31:06+00:00 2026-06-15T17:31:06+00:00

import MySQLdb import pyodbc typesFile = open(‘servinfo.txt’, ‘r’).readlines() dataTypes = dict((row.split(‘,’)[0].strip(),row.split(‘,’)[1].strip()) for row in

  • 0
import MySQLdb
import pyodbc


typesFile = open('servinfo.txt', 'r').readlines()
dataTypes = dict((row.split(',')[0].strip(),row.split(',')[1].strip()) for row in typesFile)   


conn = pyodbc.connect('DRIVER={FreeTDS}; SERVER=prsoft; DATABASE=blueseas; UID=sa;    PWD=tiger')
msCursor = conn.cursor()


db = MySQLdb.connect(passwd="pr", db="tenable")
myCursor = db.cursor()

msCursor.execute("SELECT * FROM airlinemaster WHERE type='U'") 
dbTables = msCursor.fetchall()
noLength = [56, 58, 61] 

for tbl in dbTables:
msCursor.execute("SELECT * FROM airlinemaster WHERE airline = air india('%s')" % tbl[0]) #syscolumns: see sysobjects above.
columns = msCursor.fetchall()
attr = ""
for col in columns:
colType = dataTypes[str(col.xtype)] 


if col.xtype == 60:
    colType = "float"
    attr += col.name +" "+ colType + "(" + str(col.length) + "),"
elif col.xtype in noLength:
    attr += col.name +" "+ colType + ","
else:
    attr += col.name +" "+ colType + "(" + str(col.length) + "),"

attr = attr[:-1]
myCursor.execute("CREATE TABLE " + tbl[0] + " (" + attr + ");") #create the new table and all columns
msCursor.execute("select * from %s" % tbl[0])
tblData = msCursor.fetchall()

#populate the new MySQL table with the data from MSSQL
for row in tblData:
fieldList = ""
for field in row:
    if field == None: 
    fieldList += "NULL,"
    else:
    field = MySQLdb.escape_string(str(field))
    fieldList += "'"+ field + "',"

fieldList = fieldList[:-1]
myCursor.execute("INSERT INTO " + tbl[0] + " VALUES (" + fieldList + ")" )

I’v tried the above code in many ways to import data.. but still keep on getting error as list index out of range.. Dont know where I’m going wrong.. how do I solve this?

 Traceback (most recent call last):
 File "C:\Python27\programs new\codes.py", line 10, in <module>
 dataTypes = dict((row.split(',')[0].strip(),row.split(',')[1].strip()) for row in typesFile)
 File "C:\Python27\programs new\codes.py", line 10, in <genexpr>
 dataTypes = dict((row.split(',')[0].strip(),row.split(',')[1].strip()) for row in typesFile)
 IndexError: list index out of range

pls help…. thnx in advance..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:31:06+00:00Added an answer on June 15, 2026 at 5:31 pm

    You have at least one row in typesFile that does not have a , comma in it:

    >>> 'line without a comma'.split(',')
    ['line without a comma']
    >>> 'line without a comma'.split(',')[1]
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    IndexError: list index out of range
    

    If servinfo.txt is supposed to be a comma-separated file with two columns, why not use the csv module to read it instead?

    import csv
    csvreader = csv.reader(open('servinfo.txt', 'rb'))
    dataTypes = dict(csvreader)
    

    That won’t solve your issue with there being a line with no comma in it in that file though, you’ll have to fix that first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import MySQLdb import sys from libdesklets.controls import Control from IDBConnection import IDBConnection class DBConnection(Control,
I can import MySQLdb from the interactive python command line but Zope gives me
>>> import MySQLdb Traceback (most recent call last): File <stdin>, line 1, in <module>
After I installed MySQLdb by sudo apt-get install python-mysqldb I can import and use
import httplib2 from urllib import urlencode h = httplib2.Http() h.add_credentials('zackster@gmail.com', 'PassWord') data = dict(key=ThisIsMyApiKeyICopiedAndPastedIt)
So I have a file that looks like so: #!/usr/bin/python import MySQLdb import subprocess
import MySQLdb x=raw_input('user> ') y=raw_input('passwd> ') db=MySQLdb.Connect(host=localhost, user=%s, passwd=%s % x,y) cursor=db.cursor() cursor.execute('GRANT ALL
my code is, import MySQLdb import collections from pymongo import Connection from config.MySQLdb import
Possible Duplicate: Python import MySQLdb error - Mac 10.6 I've tried everything I can
Hi I have the following error when trying to import MySQLdb. Does anyone know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.