Python论坛  - 讨论区

标题:[python-chinese] HTML writer

2006年10月16日 星期一 12:54

Bruce Wang number5在gmail.com
星期一 十月 16 12:54:21 HKT 2006

On 10/16/06, Beinan Li <li.beinan在gmail.com> wrote:
>
> ¸Õ×°ÁËelementtree, ÔËÐиÿâÖ÷Ò³ÉÏÀý³Ì³ö´í,
>
> import elementtree.ElementTree as ET
> # build a tree structure
> root = ET.Element("html")
> head = ET.SubElement(root, "head")
> title = ET.SubElement(head, "title")
> title.text = "Page Title"
> body = ET.SubElement(root, "body")
> body.set("bgcolor", "#ffffff")
> body.text = "Hello, World!"
>
> # wrap it in an ElementTree instance, and save as XML
> tree = ET.ElementTree(root)
> tree.write("page.xhtml")
>
> ÒÔÏÂÊÇ´íÎóÐÅÏ¢:
> IndexError: list index out of range
>
> Traceback (innermost last):
>
> File "i:\code\python\untitled-1.py", line 1, in ?
> import time, sys, os, os.path, locale, fnmatch, winsound
> File "i:\code\python\untitled-1.py", line 17, in ?
> ET.ElementTree(root).write("test.html")



[snip]

>
> ûÀíÓÉ°É..
>
>
µÄÈ·ÊÇûÀíÓÉ, ÎÒÔÚÎÒ»úÆ÷ÉÏÔËÐÐʲô´í¶¼Ã»ÓÐ

¿´ÄãµÄ³ö´ítraceback, ´úÂëºÃÏñºÍÀý×Ó²»Í¬, Òª²»°ÑÄã×Ô¼ºµÄ´úÂëÌùÉÏÀ´

-- 
simple is good
http://brucewang.net
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20061016/5285cf10/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号