从这个程序中获取多个错误?

时间:2012-02-15 07:00:23

标签: python sqlite config

这是我的python程序!我希望你能够明白 。 。

import sqlite3 as sqlite
import ConfigParser

config = ConfigParser.RawConfigParser()
config.read('listofcompdb.ini')

con = sqlite.connect('listofcomp.sqlite')
cur = con.cursor()

def loadtodb():
    txtfile = open('loc.txt', 'r')
    for line in txtfile:
            line = line.replace('\n','')
            u = unicode(line,'utf-8')
            cur.execute('insert or ignore into originallist(Names) values(?)',(u,))
    con.commit()

def arrangetransforms():
    print 'Preparing list of transforms to be applied'
    print 'Please Wait . . . . . '
    cur.execute('drop table transforms')
    cur.execute('create table transforms (Transform Varchar)')
    translist=config.get('Transform_Variables', 'Translist')
    cur.execute('Insert into transforms (Transform) values (\'' + translist + '\')')


def transremovechars():
    cur.execute('drop table result')
    cur.execute('Create table result (S_ID Integer,T_ID Integer,Transresult1 varchar,isdone integer)')
    char_cfg = config.get('Transform_Variables', 'Chars_to_be_removed')      #Reads all the special chars to be removed from specialchars.txt#
    cur.execute('select * from originallist')
    for row in cur:                                                         #Applies transformation to remove chars for each row in a loop#
            company = row[0]
            for specialchars in char_cfg:
                    company =  company.replace(specialchars, '')
                    print company
            cur.execute('Insert into result (Transresult1) values (?)', company)
    con.commit()                    

def transtolower():
    cur.execute('select Transresult1 from transforms')                      #Transformation to convert all the namesto lower cases#
    for row in cur:
            company1 = row[0]
            company1 = company1.lower()                                         #Creates another table named transform2#
            print company1
            cur.execute('Insert into transforms (Transresult2) values (\'' + company1 + '\')')         #Copies all the lower cased names to transform2#
    con.commit()


if __name__=="__main__":

loadtodb()
arrangetransforms()
transremovechars()
transtolower()

上面的程序是要完成多个转换的程序

但是,我得到如下输出。 。

Preparing list of transforms to be applied
Please Wait . . . . . 
AMB Ltd
AMB Ltd
AMB Ltd
AMB Ltd
AMB Ltd
AMB Ltd
AMB Ltd
AMB Ltd
Traceback (most recent call last):
  File "C:\Python26\tranfiledb.py", line 54, in <module>
    transremovechars()
  File "C:\Python26\tranfiledb.py", line 37, in transremovechars
    cur.execute('Insert into result (Transresult1) values (?)', company)
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 7 supplied.
  

我的问题

     

Cursor不读取每一行

     

行未插入数据库

1 个答案:

答案 0 :(得分:1)

cur.execute('Insert into result (Transresult1) values (?)', company)

应该是......

cur.execute('Insert into result (Transresult1) values (?)', (company,))