python formatter模块
formatter 模块
formatter 模块提供了一些可用于 htmllib 的格式类( formatter classes ).
这些类有两种, formatter 和 writer . formatter 将 HTML 解析器的标签和数据流转换为适合输出设备的事件流( event stream ), 而 writer 将事件流输出到设备上.
大多情况下, 你可以使用 AbstractFormatter 类进行格式化. 它会根据不同的格式化事件调用 writer 对象的方法. AbstractWriter 类在每次方法调用时打印一条信息.
使用 formatter 模块将 HTML 转换为事件流
!/usr/bin/python
import formatter
import htmllib
w=formatter.AbstractWriter() #writer将事件流输出到设备上
f=formatter.AbstractFormatter(w) #formatter将HTML解析器的标签和数据流转换为适合输出的事件流
file=open("index.html")
p=htmllib.HTMLParser(f)
p.feed(file.read())
p.close()
file.close()
运行结果:
windyang@windyang-desktop:~/python$ python formatter-example-1.py
send_flowing_data('\xa0')
send_line_break()
send_paragraph(1)
new_font(('h1', 0, 1, 0))
send_flowing_data('Dive Into Python')
send_line_break()
send_paragraph(1)
new_font(None)
send_flowing_data('Python from novice to pro')
send_line_break()
send_paragraph(1)
send_flowing_data('Find:')
send_flowing_data('\xa0')
send_line_break()
send_paragraph(1)
new_font(('h2', 0, 1, 0))
new_font(None)
new_font((None, 1, None, None))
send_flowing_data('Dive Into')
send_flowing_data(' Python')
new_font(None)
send_flowing_data(' is a free')
send_flowing_data(' Python')
send_flowing_data(' book for experienced programmers. You can')
send_flowing_data(' read the book')
send_flowing_data('[1]')
send_flowing_data(' online, or')
send_flowing_data(' download it')
send_flowing_data('[2]')
send_flowing_data(' in a variety of formats. It is also available in')
send_flowing_data(' multiple languages')
send_flowing_data('[3]')
send_flowing_data('.')
send_line_break()
send_paragraph(1)
new_font(('h2', 0, 1, 0))
send_flowing_data('Read')
send_flowing_data(' ')
new_font(('h2', 1, 1, 0))
send_flowing_data('Dive Into')
send_flowing_data(' Python')
new_fo
相关文档:
为了让UE支持python语言,google了很多,结果都不行,最后看了下面的博客才知道错哪了,总结下以免忘记。
http://wangtao.name/2009/12/20/ultraedit_python.html
在官网上找到python的扩展下载点:http://www.ultraedit.com/downloads/extras.html
有各种语言的扩展,便可以支持语法高亮。
python 2.5:http://www.u ......
今天试验使用python连接 sql server 服务器。我记得以前使用ado连接access非常顺利,但是今天使用ado连接sql server竟然不成功。在python里面的出错信息都显示为转移序列,费了半天劲才搞明白:无效的类别字符串。
是连接字符串吗?测试了好几个 确认无误的数据库连接字符串,也是如此 。上网搜索,是有可能是 com的类别字 ......
Python 元组
元组和列表十分类似,只不过元组和字符串一样是 不可变的 即你不能修改元组。元组通过圆括号中用逗号分割的项目定义。元组通常用在使语句或用户定义的函数能够安全地采用一组值的时候,即被使用的元组的值不会改变。
使用元组
例9.2 使用元组
#!/usr/bin/python
# Filename: using_tuple.py
zoo = ('wo ......
从去年还没毕业就接触Python,上周有些无聊重新再看一遍,发现其确实不错。语法简单,一个下午基本了解,使用Pydev插件在Eclipse中进行开发基本上没有任何障碍。重点是其效率很高,不需编译直接运行。比较适合进行数据的预处理。不错,以后有机会好好用用。 ......
第一步:搭建手机运行平台
要在S60手机上运行PY开发的软件,首先就要搭建手机PY运行环境.诺基亚手机本身不支持Python,所以要安装Python插件.
PS:一定要安装在C盘!我一开始装E,结果出现了很严重的问题!不过,最近网上发现有E盘版的啦,你可以自己试验一下,哈哈
PythonScriptShell_1_4_5_3rdEd.SIS
Pyth ......