我有一个文件' main.py',代码为:
import CreatingTable
CreatingTable.Creating()
我收到以下错误:
在下面的CreatingData.py代码中,有一些文本文件,其中包含如下数据:
CreateTable.txt包含Sheet1,SNo,描述
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
文件:&#39; CreatingTable.py&#39;:
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))