Python CGI:如何将大输出拆分为页面?

发布于 2024-12-05 12:30:20 字数 405 浏览 1 评论 0原文

如何将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱情眠于流年 2024-12-12 12:30:20

粗略地概括一下如何进行:

  1. 您必须将参数 page 编码到您的网址中,该参数表示:“显示页码 page”。这类似于 http://xxx.abc.de/genes?page=3,您必须修改脚本才能检索此参数。这可以通过 http://docs.python.org/library/urlparse.html#< 来完成/a>

  2. 您必须修改您的选择,以便检索元素 page ... page+pagesize-1 。 MySQL 为此提供了 limit 修饰符。请参阅http://dev.mysql.com/doc/refman/5.1/ en/select.html

  3. 您必须在页面上生成链接到上一页和下一页(如果存在)的链接。根据上面的示例,这将是 http://xxx.abc.de/genes?page=2http://xxx.abc.de/genes?page=4< /code>

A rough sketch how to proceed:

  1. You have to code a parameter page into your url, which indicates: "show the page number page". This is something like http://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#

  2. You have to modify your selects, such that elements page ... page+pagesize-1 are retrieved. MySQL has the limit modifier for this. See http://dev.mysql.com/doc/refman/5.1/en/select.html

  3. You 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 and http://xxx.abc.de/genes?page=4

蓝眼睛不忧郁 2024-12-12 12:30:20

使用“LIMIT offset,limit”sql语句。您还可以缓冲输出,并按页(文件)写入数据

Use "LIMIT offset,limit" sql statement. Also you can buffer your output, and write data breaking it by pages(files)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文