python变量赋值不合法_python中变量赋值语法错误

在尝试使用Python导入并执行CreatingTable模块时遇到了语法错误。错误出现在'CreatingTable.py'文件的第27行,具体是'l = len(s)'这句代码。问题可能在于`s`变量未定义或赋值不正确。代码从多个文本文件读取数据,包括数据库连接信息和表格创建详情,然后使用MySQLdb模块连接数据库并创建表。错误表明在执行ALTER TABLE语句前,需要确保`s`变量已经正确初始化并包含了足够的元素。
摘要由CSDN通过智能技术生成

我有一份档案,'主.py,代码为:import CreatingTable

CreatingTable.Creating()

我得到以下错误:

在以下代码中创建数据.py其中包含以下数据的文本文件:在连接数据.txt有localhost,root,FundManagement

在密码.txt有密码

在创建表.txt有表1,无,说明Traceback (most recent call last):

File "main.py", line 1, in

import CreatingTable

File"/home/tamal/Desktop/Python/FundManagement/FundManagement/CreatingTable.py", line 27

l = len(s)

^ SyntaxError: invalid syntax

文件:'创建表.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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值