Python CGI:如何将大输出拆分为页面?
如何将 python-cgi 输出拆分为页面。 循环结构示例:
While 1:
if x is true:
c.execute("select m from n where id=%s")
gene=c.fetchall()
print "%s", (gene),
else:
print "NA"
if y is true:
c.execute("select p from q where id=%s")
protein=c.fetchall()
print "%s", (protein),
else:
print "NA"
print "\n"
输出数百万行。我想将输出分成几页......比如每页 50 行。我该怎么做?我很感激你的帮助。谢谢。
How do i split the python-cgi output into pages.
sample loop structure:
While 1:
if x is true:
c.execute("select m from n where id=%s")
gene=c.fetchall()
print "%s", (gene),
else:
print "NA"
if y is true:
c.execute("select p from q where id=%s")
protein=c.fetchall()
print "%s", (protein),
else:
print "NA"
print "\n"
the output is millions of lines. I want to breakdown the output into pages..like 50 lines per page. How do i do that? I appreciate your help. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
粗略地概括一下如何进行:
您必须将参数
page
编码到您的网址中,该参数表示:“显示页码page
”。这类似于http://xxx.abc.de/genes?page=3
,您必须修改脚本才能检索此参数。这可以通过 http://docs.python.org/library/urlparse.html#< 来完成/a>您必须修改您的选择,以便检索元素
page ... page+pagesize-1
。 MySQL 为此提供了limit
修饰符。请参阅http://dev.mysql.com/doc/refman/5.1/ en/select.html您必须在页面上生成链接到上一页和下一页(如果存在)的链接。根据上面的示例,这将是
http://xxx.abc.de/genes?page=2
和http://xxx.abc.de/genes?page=4< /code>
A rough sketch how to proceed:
You have to code a parameter
page
into your url, which indicates: "show the page numberpage
". This is something likehttp://xxx.abc.de/genes?page=3
, and you have to modify your script to retrieve this parameter. This can be done with http://docs.python.org/library/urlparse.html#You have to modify your selects, such that elements
page ... page+pagesize-1
are retrieved. MySQL has thelimit
modifier for this. See http://dev.mysql.com/doc/refman/5.1/en/select.htmlYou have to generate links on your page which link to the previous page and to the following (if they exist). According to the example above this would be
http://xxx.abc.de/genes?page=2
andhttp://xxx.abc.de/genes?page=4
使用“LIMIT offset,limit”sql语句。您还可以缓冲输出,并按页(文件)写入数据
Use "LIMIT offset,limit" sql statement. Also you can buffer your output, and write data breaking it by pages(files)