开发细节
1.MySQLdb模块,建立完连接,创建cursor的时候,可以指定cursor的类型
默认类型的cursor,也就是下面这种方式
cursor = conn.cursor()
在用select语句选择一些row出来之后,不能用column的名称来引用值,只能用位置序号,比如下面的select
select ip_range,filter_detail from %s.%s where filter_id=%s limit 1
只能用row[0],row[1]这样的方式来引用ip_range,filter_detail的值。
实际上cursor函数还接受一个指定cursor类型的参数,创建cursor的语句可以写成下面这样子
cursor = conn.cursor(cursorclass = MySQLdb.cursors.DictCursor)
然后就可以用row['ip_range'],row['filter_detail']来引用select出来的值了

浙公网安备 33010602011771号