Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 modules : os, subprocess and commands

1. What’s the difference between all of the os.popen() methods?
popen2 doesn't capture standard error, popen3 does capture standard
error and gives a unique file handle for it. Finally, popen4 captures
standard error but includes it in the same file object as standard
output.
os.popen()&n ......

Python ×Öµä

Python ×Öµä
 
×ÖµäÀàËÆÓÚÄãͨ¹ýÁªÏµÈËÃû×Ö²éÕÒµØÖ·ºÍÁªÏµÈËÏêϸÇé¿öµÄµØÖ·²¾£¬¼´£¬ÎÒÃǰѼü£¨Ãû×Ö£©ºÍÖµ£¨ÏêϸÇé¿ö£©ÁªÏµÔÚÒ»Æð¡£×¢Ò⣬¼ü±ØÐëÊÇΨһµÄ£¬¾ÍÏñÈç¹ûÓÐÁ½¸öÈËÇ¡ÇÉͬÃûµÄ»°£¬ÄãÎÞ·¨ÕÒµ½ÕýÈ·µÄÐÅÏ¢¡£
×¢Ò⣬ÄãÖ»ÄÜʹÓò»¿É±äµÄ¶ÔÏ󣨱ÈÈç×Ö·û´®£©À´×÷Ϊ×ÖµäµÄ¼ü£¬µ«ÊÇÄã¿ÉÒÔ²»¿É±ä»ò¿É±äµÄ¶ÔÏó×÷Ϊ×Öµäµ ......

Python±àÂë¹æ·¶


±ê׼ͷ²¿
#!/usr/bin/python
±àÂë
ËùÓÐµÄ Python ½Å±¾Îļþ¶¼Ó¦ÔÚÎļþÍ·±êÉÏ #-*- coding:utf8 -*- ¡£ÉèÖñ༭Æ÷£¬Ä¬Èϱ£´æΪ utf8 ¸ñʽ¡£
mainº¯Êý
Ó¦ÓóÌÐòÒª¶¨Òåmainº¯Êý¶ø²»ÒªÖ±½Óд½Å±¾
def main():
dosomething()
if
__name__ == "__main__"
:
main()
Èç¹ûÊÇÈ«¾Ö±äÁ¿£¬ÔòÐèÒªÏÔʽ¼ÓÉ ......

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ºÅ