Eu tenho um arquivo, main.py
, com código como:
import CreatingTable
CreatingTable.Creating()
Eu recebo o seguinte erro:
No código a seguir de CreatingData.py
, há arquivos de texto com dados neles da seguinte forma:
ConnectionData.txt
tem localhost,root,FundManagement
password.txt
tem password
CreateTable.txt
tem Sheet1,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
O arquivo: 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))