日期:2014-05-16  浏览次数:20489 次

python使用MySQLdb模块的一些记录
刚接触python ,很多不懂的。偶E文也很烂,所以帮助文档也基本上是靠蒙。

今天刚刚从网络上看到了MySQLdb模块,试着安装后写了下面的查询语句,怎么才能让显示的结果一行行的,而不是每个行之间有空行呢?
代码如下:
#coding:utf-8
#filename:MySQL.py
#use:test to connect MySQL,and operation the MySQL datebase

import MySQLdb

#define some var
hostname = "localhost"
username = "root"
password =  ""
dbname = "python"

conn = MySQLdb.connect(host = hostname,user = username ,passwd= password,db = dbname,charset='utf8')
cursor = conn.cursor()

sql = "select * from test"
cursor.execute(sql)
row = cursor.fetchall()
for a in row:
	for b in a:
		print b,
	print "\n"