易截截图软件、单文件、免安装、纯绿色、仅160KB

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


相关文档:

Python标准库 traceback模块

Example 2-18 展示了 traceback 模块允许你在程序里打印异常的跟踪返回
(Traceback)信息, 类似未捕获异常时解释器所做的. 如 Example 2-18 所示. 2.11.0.1. Example
2-18. 使用 traceback 模块打印跟踪返回信息 File: traceback-example-1.py # note!
import
Example 2-18 展示了 traceback 模块允许你在程序里打印异常 ......

vim python 的path环境变量

以前也写过一些关于 vim 环境变量的内容,使用 vim 和 python ,每一段时间后都会有新的体会,所以要不断总结了.
vim 针对 python 的万能补全: vim 当前进程需要找到相应补全模块库所在位置,此是就和 python 的path环境变量相关。
python 代码运行时: 对于import 的模块也需要确定它的具体位置,python 解释器会到当前路 ......

UltraEdit支持python语言。


为了让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 序列


Python 序列
列表、元组和字符串都是序列,但是序列是什么,它们为什么如此特别呢?序列的两个主要特点是索引操作符和切片操作符。索引操作符让我们可以从序列中抓取一个特定项目。切片操作符让我们能够获取序列的一个切片,即一部分序列。
使用序列
例9.5 使用序列
#!/usr/bin/python
# Filename: seq.py
shoplist ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号