易截截图软件、单文件、免安装、纯绿色、仅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图形处理库PIL(Python Image Library)


原文地址 http://www.javaeye.com/wiki/Python/1371-python-graphics-library-pil-python-image-library-introduction
关于PIL库的一些概念
pil能处理的图片
类型
pil可以处理光栅图片(像素数据组成的的块)。
通道
一个图片可以包含一到多个数据通道,如果这些通道具有相同的维数和深度,Pil允许将这些通道进行叠加 ......

python访问 sql server

今天试验使用python连接 sql server 服务器。我记得以前使用ado连接access非常顺利,但是今天使用ado连接sql server竟然不成功。在python里面的出错信息都显示为转移序列,费了半天劲才搞明白:无效的类别字符串。
是连接字符串吗?测试了好几个 确认无误的数据库连接字符串,也是如此 。上网搜索,是有可能是 com的类别字 ......

Python 字符串


Python 字符串
字符串是 字符的序列 。字符串基本上就是一组单词。
我几乎可以保证你在每个Python程序中都要用到字符串,所以请特别留心下面这部分的内容。下面告诉你如何在Python中使用字符串。
使用单引号(')
你可以用单引号指示字符串,就如同'Quote me on this'这样。所有的空白,即空格和制表符都照原样保留。 ......

Amusing Python 2: range/xrange

这两个基本上都是在循环的时候用。
Python
代码 < type="application/x-shockwave-flash" width="14" height="15" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" src="http://cloudhe.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" flashvars="clipboard=for%20i% ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号