ubuntu 12.04中python中的变量赋值语法错误

ubuntu 12.04中python中的变量赋值语法错误

我有一个文件,main.py其代码如下:

import CreatingTable
CreatingTable.Creating()

我收到以下错误:

在下面的代码中,CreatingData.py有包含如下数据的文本文件:

  • ConnectionData.txtlocalhost,root,FundManagement
  • password.txtpassword
  • CreateTable.txtSheet1,SNo,Description
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import CreatingTable
  File "/home/tamal/Desktop/Python/FundManagement/FundManagement/CreatingTable.py", line 27
    l = len(s) 
    ^
SyntaxError: invalid syntax

文件:CreatingTable.py

import MySQLdb

def Creating():
    file02 = open("ConnectionData.txt", "r+")
    strFile = file02.readline()
    s = strFile.split(',')
    file02.close()
    file03 = open("password.txt", "r+")
    pasword = file03.readline()
    file03.close()
    host = s.pop(0)
    user = s.pop(0)
    database = s.pop(0)
    host = str(host)
    user = str(user)
    database = str(database)
    password = str(password)
    conn = MySQLdb.connect(host, user, password, database) 
    cur = conn.cursor() 
    file04 = open("CreateTable.txt", "r+")
    strFile1 = file04.readline()
    file04.close()
    s = strFile1.split(',')
    table = s[0]         
    column = s[1]
    cur.execute("CREATE TABLE %s (%s)" % (table, column))
    l = len(s)   
    for i in range(2, l):
        column = s[i]
        cur.execute("ALTER TABLE %s ADD COLUMN %s" % (table, column))

相关内容