- 论坛徽章:
- 0
|
本帖最后由 xduck 于 2012-10-24 20:46 编辑
各位前辈好,我碰到一个问题。
是这样的,关于从mysql里面读取数据然后格式化输出到终端。
数据库里面的数据如下
最后的输出时如下的样式
下面是代码- # -*- coding: utf-8 -*-
- import MySQLdb
- conn = MySQLdb.connect(host='localhost',user='root',passwd=' 110 ',db='first',charset='utf8')
- cursor = conn.cursor()
- cursor.execute('select * from Products')
- numrows = int(cursor.rowcount)
- for i in range(numrows):
- row = cursor.fetchone()
- print "%s %s %s" %(row[0],row[2],row[1])
- cursor.close()
- conn.close()
复制代码 我想最后在终端的输出是对齐的,就是那个尺码,左对齐或者右对齐,但是对语言还不太熟悉,冒昧哪位前辈指点下。谢谢 |
|