psycopg2方法抱怨参数

时间:2014-07-24 05:23:37

标签: psycopg2 python-3.4

我不能为我的生活找出为什么我的python脚本抱怨下面的方法

def insert_file_into_db(connection, f):
    #print(f.read())
    cur = connection.cursor()
    cur.execute("DELETE FROM mnemonics;") # clean up db before new copy
    next(f) # skip the default group on the first line
    for line in f.readlines():
        system     = line[0:3].strip()
        mnemonic   = line[5:8].strip()
        department = line[9:69].strip()
        team       = line[69:139].strip()
        lob        = line[139:190].strip()
        #print(s, ' ', m, ' ', d, ' ', t, ' ', l)
        cur.execute("INSERT INTO mnemonics VALUES (%s, %s, %s, %s, %s)",
                         system, mnemonic, department, team, lob)
    cur.close()

def main():
    pw = open('S104838.txt', 'r')
    con_S104838 = connect_db("S104838", "S104838",
                             pw.readline().strip(),
                             "1.1.1.1", "5432")
    insert_file_into_db(con_S104838, open('TEAM_MNEMONIC.txt','r+'))

运行时出现以下错误

C:\mnemonics>python main.py
Traceback (most recent call last):
  File "main.py", line 37, in <module>
    sys.exit(main())
  File "main.py", line 34, in main
    insert_file_into_db(con_S104838, open('TEAM_MNEMONIC.txt','r+'))
  File "main.py", line 26, in insert_file_into_db
    system, mnemonic, department, team, lob)
TypeError: function takes at most 2 arguments (6 given)

花了一些时间在谷歌搜索这个不确定会有什么帮助将会非常感激

0 个答案:

没有答案