<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>没有比人更高的山 &#187; Python</title>
	<atom:link href="http://www.zhlwish.com/category/py/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zhlwish.com</link>
	<description>Where there is a will there is a way.</description>
	<lastBuildDate>Fri, 13 Jan 2012 08:13:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>XMPP中资源/Resource的解释和JID</title>
		<link>http://www.zhlwish.com/2011/09/23/xmpp_resource_jid/</link>
		<comments>http://www.zhlwish.com/2011/09/23/xmpp_resource_jid/#comments</comments>
		<pubDate>Fri, 23 Sep 2011 08:31:20 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=816</guid>
		<description><![CDATA[因为之前写过《使用PyXMPP向GTalk发送消息》一文，最近被一个研究XMPP协议的学妹问到XMPP协议中的资源（Resource）的意思。其实我开始也是一知半解，而且学妹挺诚心的样子，就仔细看了看XMPP协议的文档，这里也感谢这位学妹提供的XMPP协议（RFC3920）的中文版和英文版，其实我以前写用pyxmpp的时候也没有仔细看XMPP协议的。 不看不知道，一看吓一跳，原来所谓的Resource和我一直很欣赏的Google Talk的多客户端同时在线的功能有关系，Google Talk就是基于XMPP协议的。 首先举几个JID的例子，比如下面几个都是完整的JID: xxx@gmail.com /gtalk-client xxx@gmail.com /plus.google.com xxx@gmail.com /gmail xxx@gmail.com /sony-errision-x10-android JID实际上是3部分组成的：节点名（上面四个JID中的“xxx”），域名（上面四个JID中的“gmail.com”，一般是主服务器的域名），资源名（上面四个JID中最后面不同的那部分） 这四个JID都对应到某人的google帐号（xxx@gmail.com），只不过一个对应windows gtalk客户端，第二个对应google plus网页的上的那个聊天窗口，第三个对应google talk的网页窗口，第四个对应手机上的google talk。注意这里资源的名字只是我自己瞎想出来的，可能一般实现的时候会直接有服务器生成一个随机字符串吧。 和QQ不一样的是，XMPP允许一个帐号在不同的地方登录，比如我的电脑、google plus网页、gmail、手机上的google talk现在都是登录状态，别人给我发送消息的时候，我的四个client都会提示我有收到新的消息，但是当我选择用手机回复的时候，本次会话（session）所有消息都会只发送到我的手机，而其他的client（如windows上的google client、gmail里面的client）就不会再收到消息了。 因此除了帐号(xxx@gmail.com)以外，会有另外一个标识符来标识我使用的这种client，这个client就是上文提到的resource，这里上面4个帐号中，email地址后面的字符串就是resource id了 因此为了确认你使用的哪一个客户端，需要resource绑定。绑定后的JID才是一个完整的JID。 上面就是我对XMPP中Resource的理解，也特别感谢这位学妹的问题，才让我对XMPP有了更深入了解的机会。]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2011/09/23/xmpp_resource_jid/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>使用PyXMPP向GTalk发送消息</title>
		<link>http://www.zhlwish.com/2011/04/04/pyxmpp_gtalk/</link>
		<comments>http://www.zhlwish.com/2011/04/04/pyxmpp_gtalk/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 07:04:40 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=339</guid>
		<description><![CDATA[2011年9月23日16:30:54 更新 关于JID，请参考XMPP中资源/Resource的解释和JID Python有2个package实现了XMPP和Jabber标准：xmpppy和 pyxmpp，哪个好就自然是一个问题。一般公认的看法是pyxmpp是首选，它完全符合XMPP协议，开发也保持活跃的状态，并且最新的版本是2010年发布的。而xmpppy则公认为设计上有不太合理之处，也不完全符合XMPP协议，所以不推荐使用，而且还是在2009年4月份更新的，开源神马的最怕不更新了！ 安装 在Ubuntu 10.10上安装pyxmpp有两种办法，一种是一步到位： sudo apt-get install python-pyxmpp 另一种是自己下载，之后安装，但是由于pyxmpp依赖python-libxml2，python-dnspython，而且在用gtalk发送消息时使用tls加密，因而还依赖python-m2crypto，所以安装过程如下： sudo apt-get install python-libxml2 sudo apt-get install python-dnspython sudo apt-get install python-m2crypto tar -xzvf pyxmpp-1.1.1.tar.gz cd pyxmpp-1.1.1 sudo python configure.py sudo python setup.py build sudo python setup.py &#8230; <a href="http://www.zhlwish.com/2011/04/04/pyxmpp_gtalk/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2011/04/04/pyxmpp_gtalk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python从命令行输入中文的编码问题</title>
		<link>http://www.zhlwish.com/2011/03/13/reading_chinese_from_cmd_in_python/</link>
		<comments>http://www.zhlwish.com/2011/03/13/reading_chinese_from_cmd_in_python/#comments</comments>
		<pubDate>Sun, 13 Mar 2011 05:52:37 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[编码]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=322</guid>
		<description><![CDATA[写了个python脚本自动完成某项工作，需要将从命令行读入的参数写到utf-8编码的文件中，在linux系统中没有问题，因为shell默认为utf-8编码格式，读入后直接写入就行，但是由于Window系统的默认编码为cp936，始终提示编码有错误 <a href="http://www.zhlwish.com/2011/03/13/reading_chinese_from_cmd_in_python/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2011/03/13/reading_chinese_from_cmd_in_python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python对象内置函数__str__</title>
		<link>http://www.zhlwish.com/2011/03/08/python_buildin_functions_str/</link>
		<comments>http://www.zhlwish.com/2011/03/08/python_buildin_functions_str/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 17:54:31 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=311</guid>
		<description><![CDATA[精通Java或者.net的同学在学习Python面向对象的时候总会思考一个问题，Python对象的toString()方法怎么写，怎么样才能print一个对象打印出友好的内容，而不是打印出内存地址？ <a href="http://www.zhlwish.com/2011/03/08/python_buildin_functions_str/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2011/03/08/python_buildin_functions_str/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python对象内置函数之__iter__</title>
		<link>http://www.zhlwish.com/2010/12/19/python_buildin_function_iter/</link>
		<comments>http://www.zhlwish.com/2010/12/19/python_buildin_function_iter/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 07:38:02 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=270</guid>
		<description><![CDATA[Python读取文件可以用以下方式： 1 2 3 with open&#40;'/path/to/file', 'r'&#41; as txtfile: for line in txtfile: print line 其中，with语句我已经非常熟悉，自从有了with，我已经彻底抛弃了下面的写法 1 2 3 4 5 txtfile = open&#40;'/path/to/file'&#41; try: alllines = txtfile.readlines&#40;&#41; finally: txtfile.close&#40;&#41; 最上面这段代码吸引我的是第二句，居然对一个文件对象进行迭代？有没有搞错！ 是的，没有搞错，之所以呢对一个文件对象进行迭代，原因就在python对象的内置函数__iter__。举个例子，有个Dictionary的类，里面有很多Word，每个Word有很多Translate，很多时候需要对词典（Dictionary）中的词（Word）进行遍历，即下面的代码： 1 2 3 dic = Dictionary&#40;&#41; for word &#8230; <a href="http://www.zhlwish.com/2010/12/19/python_buildin_function_iter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2010/12/19/python_buildin_function_iter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python规整XML文件</title>
		<link>http://www.zhlwish.com/2010/12/15/python_tidy_xml/</link>
		<comments>http://www.zhlwish.com/2010/12/15/python_tidy_xml/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 09:16:28 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=268</guid>
		<description><![CDATA[工作需要，简单实现了一个用python把格式混乱的xml文件规整为人类可读的格式 import codecs import sys import os.path &#160; from xml.dom.minidom import parse from xml.dom import Node &#160; def remove_whitespace_nodes&#40;node&#41;: remove_list = &#91;&#93; for child in node.childNodes: if child.nodeType==Node.TEXT_NODE and not child.data.strip&#40;&#41;: remove_list.append&#40;child&#41; elif child.hasChildNodes&#40;&#41;: remove_whitespace_nodes&#40;child&#41; &#160; for node in remove_list: &#8230; <a href="http://www.zhlwish.com/2010/12/15/python_tidy_xml/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2010/12/15/python_tidy_xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python创建特定编码格式的文件</title>
		<link>http://www.zhlwish.com/2010/12/13/python_create_utf8_file/</link>
		<comments>http://www.zhlwish.com/2010/12/13/python_create_utf8_file/#comments</comments>
		<pubDate>Sun, 12 Dec 2010 16:24:01 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[编码]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=266</guid>
		<description><![CDATA[话说内置open方法只能创建asiic编码的文件，其函数签名为：open(filename[, mode[, bufsize]])，简单示例如下： 1 2 3 file = open&#40;'dist.txt', 'r'&#41; file.write&#40;'some text'&#41; file.close&#40;&#41; 但是，如果需要创建一个UTF-8编码格式的文件怎么办呢，只能求助于codes模块的open方法了，其签名如下：codecs.open(filename, mode[, encoding[, errors[, buffering]]])，very impressive，示例如下： 1 2 3 file = open&#40;'dist.txt', 'r', 'urf-8'&#41; file.write&#40;u'一些unicode文本'&#41; file.close&#40;&#41; 本文是本博客原创文章，您可以自由转载，但转载请注明来源。]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2010/12/13/python_create_utf8_file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python使用SQLite数据库简明教程</title>
		<link>http://www.zhlwish.com/2010/10/13/python_sqlite/</link>
		<comments>http://www.zhlwish.com/2010/10/13/python_sqlite/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 12:47:58 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=246</guid>
		<description><![CDATA[建立数据库连接： 1 conn = sqlite3.connect&#40;db_path&#41; 建立内存数据库： 1 conn = sqlite3.connect&#40;':memory:'&#41; 获取Cursor对象，Cursor用于执行sql： 1 2 cur = conn.cursor&#40;&#41; cur.execute&#40;sql&#41; Cursor.excute(sql[, param])支持?占位符，如： 1 c. execute&#40;'select * from students where name=?', name&#41; 而且这是推荐的安全方式，可以避免sql注入，不推荐使用字符串拼接 读取数据的方式有以下几种： 1. 可以直接遍历Cursor对象，如 1 2 3 cur.execute&#40;sql&#41; for row in cur: &#8230; <a href="http://www.zhlwish.com/2010/10/13/python_sqlite/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2010/10/13/python_sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Python生成文件的MD5校验码</title>
		<link>http://www.zhlwish.com/2010/10/11/python_file_md5/</link>
		<comments>http://www.zhlwish.com/2010/10/11/python_file_md5/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 13:50:28 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[md5]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=243</guid>
		<description><![CDATA[Python中，用于加密的md5方法在hashlib模块中，使用非常简单： from hashlib import md5 &#160; m = md5&#40;&#41; #获取一个MD5加密算法对象 m.update&#40;'string'&#41; #指定要加密的字符串 m.hexdigest&#40;&#41; #获取加密后的16进制字符串 文件的MD5校验码是根据文件的内容生成的信息摘要，方法如下， from hashlib import md5 &#160; def md5_file&#40;name&#41;: m = md5&#40;&#41; a_file = open&#40;name, 'rb'&#41; #需要使用二进制格式读取文件内容 m.update&#40;a_file.read&#40;&#41;&#41; a_file.close&#40;&#41; return m.hexdigest&#40;&#41; &#160; if __main__ == '__init__': print &#8230; <a href="http://www.zhlwish.com/2010/10/11/python_file_md5/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2010/10/11/python_file_md5/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>用Python修改Excel文件</title>
		<link>http://www.zhlwish.com/2010/10/09/python_edit_excel/</link>
		<comments>http://www.zhlwish.com/2010/10/09/python_edit_excel/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 12:07:10 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=238</guid>
		<description><![CDATA[Python中一般使用xlrd（excel read）来读取Excel文件，使用xlwt（excel write）来生成Excel文件（可以控制Excel中单元格的格式），需要注意的是，用xlrd读取excel是不能对其进行操作的：xlrd.open_workbook()方法返回xlrd.Book类型，是只读的，不能对其进行操作。而xlwt.Workbook()返回的xlwt.Workbook类型的save(filepath)方法可以保存excel文件。 因此对于读取和生成Excel文件都非常容易处理，但是对于已经存在的Excel文件进行修改就比较麻烦了。不过，还有一个xlutils（依赖于xlrd和xlwt）提供复制excel文件内容和修改文件的功能。其实际也只是在xlrd.Book和xlwt.Workbook之间建立了一个管道而已，如下图： xlutils.copy模块的copy()方法实现了这个功能，示例代码如下： from xlrd import open_workbook from xlutils.copy import copy &#160; rb = open_workbook&#40;'m:\\1.xls'&#41; &#160; #通过sheet_by_index()获取的sheet没有write()方法 rs = rb.sheet_by_index&#40;0&#41; &#160; wb = copy&#40;rb&#41; &#160; #通过get_sheet()获取的sheet有write()方法 ws = wb.get_sheet&#40;0&#41; ws.write&#40;0, 0, 'changed!'&#41; &#160; wb.save&#40;'m:\\1.xls'&#41; 参考： Python Excel：http://www.python-excel.org/ xlrd：Download &#8230; <a href="http://www.zhlwish.com/2010/10/09/python_edit_excel/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2010/10/09/python_edit_excel/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>彩色标签云的生成方法</title>
		<link>http://www.zhlwish.com/2009/11/15/colorful-tag/</link>
		<comments>http://www.zhlwish.com/2009/11/15/colorful-tag/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 01:23:38 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[google app engine]]></category>
		<category><![CDATA[web前端]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=49</guid>
		<description><![CDATA[发现欧必杰（http://www.ooobj.com/blog）的标签远远比我多，用li列表显示已经不可容忍，所以我决定花点时间把标签的显示更新一下，最新的效果如http://zhlwish.appspot.com左侧的标签云。 思路很简单，就是为每个标签随机生成一种颜色（当然要考虑到如果生成的背景色，就需要再生成一次），然后根据引用这个标签的日志数按比例生成12-15号之间的字体。具体的代码如下： 这里偷了个懒，我这里的标签云是白色背景，就直接硬编码了，最好是作为列表参数传入。 这里遇到了一个问题就是python的除法问题，python有两种除法，即所谓的true除法和floor除法，有兴趣的朋友google一下啦。我就不重复占用网络资源了。 import random def rand_color():     hex_char = ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')     color = "#"     for i in range(6):         color += random.choice(hex_char) &#8230; <a href="http://www.zhlwish.com/2009/11/15/colorful-tag/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2009/11/15/colorful-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google App Engine中开发中复用Django的syndication生成RSS</title>
		<link>http://www.zhlwish.com/2009/11/15/google-app-engine-rss/</link>
		<comments>http://www.zhlwish.com/2009/11/15/google-app-engine-rss/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 00:40:40 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[google app engine]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=19</guid>
		<description><![CDATA[因为django.contrib.syndication.feeds用到了from django.contrib.sites.models import Site, RequestSite，而其中的Site和RequestSite又用到了Django的db模块，因此在GAE中是不能用的，看了看源代码，发现其实这两个类是可以不用的，于是我就想改动改动Django的代码来实现。 <a href="http://www.zhlwish.com/2009/11/15/google-app-engine-rss/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2009/11/15/google-app-engine-rss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google App Engine中的多对多关联</title>
		<link>http://www.zhlwish.com/2009/11/15/google-app-engine-many-to-many/</link>
		<comments>http://www.zhlwish.com/2009/11/15/google-app-engine-many-to-many/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 22:23:38 +0000</pubDate>
		<dc:creator>周亮</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[google app engine]]></category>

		<guid isPermaLink="false">http://www.zhlwish.com/?p=9</guid>
		<description><![CDATA[Google App Engine(GAE)中使用db.ReferenceProperty来处理实体之间的一对多关联，如Diary（日志）和Category（分类）是多对一的关系，可以简单配置如下： 1 2 3 4 5 6 7 8 class Category&#40;db.Model&#41;:     name = db.StringProperty&#40; required = True&#41; &#60;code&#62; class Diary&#40;db.Model&#41;:     title = db.StringProperty&#40; required = True &#41;     content = db.TextProperty&#40;&#41;     category = db.ReferenceProperty&#40;Category&#41; &#60;/code&#62; 这样可以使用diary.category即可获取Diary（日志）所对应的Category（分类），使用category.diary_set即可获取Category（分类）所对应的Diary（日志） 但是再处理Tag（标签）和Diary（日志）时出现了问题，因为GAE并没有多对多关联，经过查询资料，可以有一种很简单的办法是在关系的其中一方创建一个的列表，如下： 1 2 &#8230; <a href="http://www.zhlwish.com/2009/11/15/google-app-engine-many-to-many/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.zhlwish.com/2009/11/15/google-app-engine-many-to-many/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

