我正在从 MySQL 数据库中读取数据并希望将其打印到屏幕上。
我用:
import MySQLdb
conn = MySQLdb.connect(host='localhost',user='root',passwd='passwd',db='test',charset='utf8')
cursor = conn.cursor()
cursor.execute('select cust_name,cust_address,cust_city,cust_state from Customers')
numrows = int(cursor.rowcount)
for i in range(numrows):
row = cursor.fetchone()
print "%s %s %s %20s" %(row[0],row[1],row[2],row[3])
cursor.close()
conn.close()
结果是这样的:
Village Toys 200 Maple Lane Detroit MI Kids Place 333 South Lake Drive Columbus OH Fun4All 1 Sunny Place Muncie IN Fun4All 829 Riverside Drive 凤凰城 玩具店 4545 53rd Street Chicago IL
我怎样才能使它左对齐?