<?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>idea&#039;s blog &#187; Python</title>
	<atom:link href="http://www.ideawu.net/blog/category/python/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ideawu.net/blog</link>
	<description>网络服务器架构, Linux C/C++服务器端开发, TCP/IP网络协议, PHP Web后端和Web前端开发, 网站架构.</description>
	<lastBuildDate>Wed, 08 Feb 2012 10:02:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Python logging 标准配置</title>
		<link>http://www.ideawu.net/blog/archives/624.html</link>
		<comments>http://www.ideawu.net/blog/archives/624.html#comments</comments>
		<pubDate>Wed, 04 Jan 2012 09:10:57 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.ideawu.net/blog/archives/624.html</guid>
		<description><![CDATA[<pre>
# encoding=UTF-8
import logging
import logging.config

logging.addLevelName(5, 'TRACE')
logging.addLevelName(30, 'WARN')
logging.addLevelName(50, 'FATAL')

logging.config.fileConfig('my.conf')
logger = logging.getLogger('root')
</pre>
<p>my.conf:</p>
<pre>
[loggers]
keys=root

[handlers]
keys=consoleHandler, fileHandler

[formatters]
keys=simpleFormatter

[logger_root]
#level=ERROR
level=DEBUG
handlers=consoleHandler, fileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
args=('a.log', 'a')

[formatter_simpleFormatter]
#format=%(asctime)s [%(levelname)-5s] %(name)s %(message)s
format=%(asctime)s [%(levelname)-5s] %(message)s
#datefmt= %Y-%m-%d %H:%M:%S
datefmt=
</pre>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/407.html' rel='bookmark' title='Permanent Link: .Net程序中使用log4net记录日志'>.Net程序中使用log4net记录日志</a></li>
<li><a href='http://www.ideawu.net/blog/archives/426.html' rel='bookmark' title='Permanent Link: C#封装log4net'>C#封装log4net</a></li>
<li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
<li><a href='http://www.ideawu.net/blog/archives/155.html' rel='bookmark' title='Permanent Link: 如何使用ServletContextListener'>如何使用ServletContextListener</a></li>
<li><a href='http://www.ideawu.net/blog/archives/270.html' rel='bookmark' title='Permanent Link: 使用Python POST任意的HTTP数据以及使用Cookie'>使用Python POST任意的HTTP数据以及使用Cookie</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/624.html" title="Python logging 标准配置">Python logging 标准配置</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<pre>
# encoding=UTF-8
import logging
import logging.config

logging.addLevelName(5, 'TRACE')
logging.addLevelName(30, 'WARN')
logging.addLevelName(50, 'FATAL')

logging.config.fileConfig('my.conf')
logger = logging.getLogger('root')
</pre>
<p>my.conf:</p>
<pre>
[loggers]
keys=root

[handlers]
keys=consoleHandler, fileHandler

[formatters]
keys=simpleFormatter

[logger_root]
#level=ERROR
level=DEBUG
handlers=consoleHandler, fileHandler

[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
level=DEBUG
formatter=simpleFormatter
args=('a.log', 'a')

[formatter_simpleFormatter]
#format=%(asctime)s [%(levelname)-5s] %(name)s %(message)s
format=%(asctime)s [%(levelname)-5s] %(message)s
#datefmt= %Y-%m-%d %H:%M:%S
datefmt=
</pre>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/407.html' rel='bookmark' title='Permanent Link: .Net程序中使用log4net记录日志'>.Net程序中使用log4net记录日志</a></li>
<li><a href='http://www.ideawu.net/blog/archives/426.html' rel='bookmark' title='Permanent Link: C#封装log4net'>C#封装log4net</a></li>
<li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
<li><a href='http://www.ideawu.net/blog/archives/155.html' rel='bookmark' title='Permanent Link: 如何使用ServletContextListener'>如何使用ServletContextListener</a></li>
<li><a href='http://www.ideawu.net/blog/archives/270.html' rel='bookmark' title='Permanent Link: 使用Python POST任意的HTTP数据以及使用Cookie'>使用Python POST任意的HTTP数据以及使用Cookie</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/624.html" title="Python logging 标准配置">Python logging 标准配置</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/624.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>endlessssh &#8211; SSH 代理工具</title>
		<link>http://www.ideawu.net/blog/archives/514.html</link>
		<comments>http://www.ideawu.net/blog/archives/514.html#comments</comments>
		<pubDate>Sun, 06 Jun 2010 07:17:22 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Computer System]]></category>
		<category><![CDATA[P2P/Network]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.ideawu.net/blog/archives/514.html</guid>
		<description><![CDATA[<p>新建了一个开源项目 endlessssh, 用于 SSH 代理(不是 SSH 作为代理, 而是 SSH 使用代理), 放在 Google Project Hosting. 工具有两个特点:</p>
<p>1. Tunneling SSH over REAL HTTP(完善中)</p>
<p>让 SSH 工作在 HTTP 协议上, 从而穿越防火墙.</p>
<p>2. 持续的会话</p>
<p>即使 TCP 网络连接断开(这时, SSH 会话会失效), SSH 会话仍然保持, 直到网络重连后, 会话继续.</p>
<p>项目地址: <a href="http://code.google.com/p/endlessssh/">http://code.google.com/p/endlessssh/</a></p>
<p><strong>补充:</strong></p>
<p>谢谢评论中 Zealot 朋友的推荐.</p>
<p>大概看了下类似的一个 GNU 项目 httptunnel(http://www.nocrew.org/software/httptunnel.html). 这个项目所使用的交互过程更像是 HTTP 交互, 在一个 HTTP 报文中包含自己的多个报文. httptunnel 没有确认机制, 也没有会话保持机制. 不过, httptunnel 可以值得借鉴.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/301.html' rel='bookmark' title='Permanent Link: Google Talk Developer Home 中文翻译'>Google Talk Developer Home 中文翻译</a></li>
<li><a href='http://www.ideawu.net/blog/archives/482.html' rel='bookmark' title='Permanent Link: 开发爬虫友好的Ajax网站'>开发爬虫友好的Ajax网站</a></li>
<li><a href='http://www.ideawu.net/blog/archives/611.html' rel='bookmark' title='Permanent Link: 强大的纯JS数据图工具-flot'>强大的纯JS数据图工具-flot</a></li>
<li><a href='http://www.ideawu.net/blog/archives/357.html' rel='bookmark' title='Permanent Link: MySQL 查询使用 Group By 的注意点'>MySQL 查询使用 Group By 的注意点</a></li>
<li><a href='http://www.ideawu.net/blog/archives/299.html' rel='bookmark' title='Permanent Link: Google Talk 界面开发分析'>Google Talk 界面开发分析</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/514.html" title="endlessssh &#8211; SSH 代理工具">endlessssh &#8211; SSH 代理工具</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<p>新建了一个开源项目 endlessssh, 用于 SSH 代理(不是 SSH 作为代理, 而是 SSH 使用代理), 放在 Google Project Hosting. 工具有两个特点:</p>
<p>1. Tunneling SSH over REAL HTTP(完善中)</p>
<p>让 SSH 工作在 HTTP 协议上, 从而穿越防火墙.</p>
<p>2. 持续的会话</p>
<p>即使 TCP 网络连接断开(这时, SSH 会话会失效), SSH 会话仍然保持, 直到网络重连后, 会话继续.</p>
<p>项目地址: <a href="http://code.google.com/p/endlessssh/">http://code.google.com/p/endlessssh/</a></p>
<p><strong>补充:</strong></p>
<p>谢谢评论中 Zealot 朋友的推荐.</p>
<p>大概看了下类似的一个 GNU 项目 httptunnel(http://www.nocrew.org/software/httptunnel.html). 这个项目所使用的交互过程更像是 HTTP 交互, 在一个 HTTP 报文中包含自己的多个报文. httptunnel 没有确认机制, 也没有会话保持机制. 不过, httptunnel 可以值得借鉴.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/301.html' rel='bookmark' title='Permanent Link: Google Talk Developer Home 中文翻译'>Google Talk Developer Home 中文翻译</a></li>
<li><a href='http://www.ideawu.net/blog/archives/482.html' rel='bookmark' title='Permanent Link: 开发爬虫友好的Ajax网站'>开发爬虫友好的Ajax网站</a></li>
<li><a href='http://www.ideawu.net/blog/archives/611.html' rel='bookmark' title='Permanent Link: 强大的纯JS数据图工具-flot'>强大的纯JS数据图工具-flot</a></li>
<li><a href='http://www.ideawu.net/blog/archives/357.html' rel='bookmark' title='Permanent Link: MySQL 查询使用 Group By 的注意点'>MySQL 查询使用 Group By 的注意点</a></li>
<li><a href='http://www.ideawu.net/blog/archives/299.html' rel='bookmark' title='Permanent Link: Google Talk 界面开发分析'>Google Talk 界面开发分析</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/514.html" title="endlessssh &#8211; SSH 代理工具">endlessssh &#8211; SSH 代理工具</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/514.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Windows Python select标准输入输出</title>
		<link>http://www.ideawu.net/blog/archives/508.html</link>
		<comments>http://www.ideawu.net/blog/archives/508.html#comments</comments>
		<pubDate>Sun, 30 May 2010 11:21:24 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Computer System]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[IO多路复用]]></category>

		<guid isPermaLink="false">http://www.ideawu.net/blog/?p=508</guid>
		<description><![CDATA[<p>Windows 版本的 Python, select() 函数只能接受 socket, <a href="http://docs.python.org/library/select.html#select.select">不接受 File Object</a>, 所以不能 select 标准输入输出.</p>
<p>为此, 我开发了 win_stdio, 让 select 也能对 stdin/stdout 进行操作. 核心思想就是用 <a href="http://docs.python.org/library/socket.html">socket</a> 作为 stdin/stdout 的代理. 结构示意如下:</p>
<pre>
stdin -&gt; stdin_sock -&gt; my_stdin
stdout &lt;- stdout_sock &lt;- my_stdout
</pre>
<p><span id="more-508"></span>my_stdin 和 my_stdout 是 socket, 所以它们的 fileno 就可以用于 select 了.</p>
<p>首先一个线程读取 stdin, 写入 stdin_sock:</p>
<pre>
while True:
	data = os.read(sys.stdin.fileno(), 1024)
	if not data:
		break
	stdin_sock.send(data)
</pre>
<p>另一个线程读取 stdout_sock, 写入 stdout:</p>
<pre>
fd = sys.stdout.fileno()
while True:
	data = my_stdout.recv(1024)
	if not data:
		break
	os.write(sys.stdout.fileno(), data)
</pre>
<p>win_stdio 的一个实际例子如下:</p>
<pre>
from stdio import stdio
stdio.write('hello world')
data = stdio.read()
print stdio.STDIN_FILENO
print stdio.STDOUT_FILENO
</pre>
<p>下载: <a href='http://www.ideawu.net/blog/wp-content/uploads/2010/05/win_stdio.zip'>win_stdio.zip</a></p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/434.html' rel='bookmark' title='Permanent Link: 最简单的JavaScript两级联动示例'>最简单的JavaScript两级联动示例</a></li>
<li><a href='http://www.ideawu.net/blog/archives/624.html' rel='bookmark' title='Permanent Link: Python logging 标准配置'>Python logging 标准配置</a></li>
<li><a href='http://www.ideawu.net/blog/archives/267.html' rel='bookmark' title='Permanent Link: 软件体系结构模式-层'>软件体系结构模式-层</a></li>
<li><a href='http://www.ideawu.net/blog/archives/270.html' rel='bookmark' title='Permanent Link: 使用Python POST任意的HTTP数据以及使用Cookie'>使用Python POST任意的HTTP数据以及使用Cookie</a></li>
<li><a href='http://www.ideawu.net/blog/archives/582.html' rel='bookmark' title='Permanent Link: PHP的continue 2'>PHP的continue 2</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/508.html" title="Windows Python select标准输入输出">Windows Python select标准输入输出</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<p>Windows 版本的 Python, select() 函数只能接受 socket, <a href="http://docs.python.org/library/select.html#select.select">不接受 File Object</a>, 所以不能 select 标准输入输出.</p>
<p>为此, 我开发了 win_stdio, 让 select 也能对 stdin/stdout 进行操作. 核心思想就是用 <a href="http://docs.python.org/library/socket.html">socket</a> 作为 stdin/stdout 的代理. 结构示意如下:</p>
<pre>
stdin -&gt; stdin_sock -&gt; my_stdin
stdout &lt;- stdout_sock &lt;- my_stdout
</pre>
<p><span id="more-508"></span>my_stdin 和 my_stdout 是 socket, 所以它们的 fileno 就可以用于 select 了.</p>
<p>首先一个线程读取 stdin, 写入 stdin_sock:</p>
<pre>
while True:
	data = os.read(sys.stdin.fileno(), 1024)
	if not data:
		break
	stdin_sock.send(data)
</pre>
<p>另一个线程读取 stdout_sock, 写入 stdout:</p>
<pre>
fd = sys.stdout.fileno()
while True:
	data = my_stdout.recv(1024)
	if not data:
		break
	os.write(sys.stdout.fileno(), data)
</pre>
<p>win_stdio 的一个实际例子如下:</p>
<pre>
from stdio import stdio
stdio.write('hello world')
data = stdio.read()
print stdio.STDIN_FILENO
print stdio.STDOUT_FILENO
</pre>
<p>下载: <a href='http://www.ideawu.net/blog/wp-content/uploads/2010/05/win_stdio.zip'>win_stdio.zip</a></p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/434.html' rel='bookmark' title='Permanent Link: 最简单的JavaScript两级联动示例'>最简单的JavaScript两级联动示例</a></li>
<li><a href='http://www.ideawu.net/blog/archives/624.html' rel='bookmark' title='Permanent Link: Python logging 标准配置'>Python logging 标准配置</a></li>
<li><a href='http://www.ideawu.net/blog/archives/267.html' rel='bookmark' title='Permanent Link: 软件体系结构模式-层'>软件体系结构模式-层</a></li>
<li><a href='http://www.ideawu.net/blog/archives/270.html' rel='bookmark' title='Permanent Link: 使用Python POST任意的HTTP数据以及使用Cookie'>使用Python POST任意的HTTP数据以及使用Cookie</a></li>
<li><a href='http://www.ideawu.net/blog/archives/582.html' rel='bookmark' title='Permanent Link: PHP的continue 2'>PHP的continue 2</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/508.html" title="Windows Python select标准输入输出">Windows Python select标准输入输出</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/508.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PyPy &#8211; 吞下自己尾巴的小蟒蛇</title>
		<link>http://www.ideawu.net/blog/archives/499.html</link>
		<comments>http://www.ideawu.net/blog/archives/499.html#comments</comments>
		<pubDate>Sun, 09 May 2010 13:30:01 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Computer System]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[PyPy]]></category>

		<guid isPermaLink="false">http://www.ideawu.net/blog/archives/499.html</guid>
		<description><![CDATA[<p><a href="http://www.ideawu.net/blog/wp-content/uploads/2010/05/snake-eat-itself.jpg"><img src="http://www.ideawu.net/blog/wp-content/uploads/2010/05/snake-eat-itself.jpg" alt="" title="snake-eat-itself" width="128" height="128" class="alignright size-full wp-image-498" /></a></p>
<p><a href="http://www.pypy.org/">PyPy</a> 项目可能会颠覆老学究和初学者的逻辑, 因为 PyPy 用 Python 语言来实现 <a href="http://docs.python.org/reference/">Python</a> 语言, 就像一只小蟒蛇吞下自己的尾巴. 也许你没见过, 但它确实存在.</p>
<p>你可能会疑惑, 既然已经有了 Python, 那么为什么还用 Python 来实现 Python(PyPy)? 后者到底是什么东西?</p>
<p>其实, 这其中的逻辑并不复杂. 比如 C 语言, C 语言的第一个编译器肯定不是用 C 语言来编写的, 但之后, C 编译器(如 GCC)就没有理由不用 C 来编写了. 所以, 用 Python 语言编写, 并用已存在的 Python 编译器(解释器, 执行环境)来做一个实现 Python 语言并没有什么奇怪.</p>
<p><span id="more-499"></span><a href="http://www.pypy.org/"><img src="http://pypy.org/image/pypy-logo.png" alt="[pypy-logo]" /></a></p>
<p>简单地说, PyPy 是用 Python 语言写了一个工具, 将 Python 代码转成 C, .NET, Java 等语言和平台的代码. PHP 也有类似的项目 &#8211; <a href="http://www.hiphop-php.com/">HipHop-PHP</a>, 把 PHP 代码转成 C++ 代码.</p>
<p>为什么要将一种语言转成另一种语言? 首先是目标语言可能在性能(如C语言)和/或跨平台(如 .NET, Java)等方面具有优势. 其次, 在转换的过程, 可以进行代码优化或加入新技术, 比如 PyPy 应用的 Just-in-Time(JIT) 技术, 能让 Python (事实上是转换后的目标代码)的执行速度更快.</p>
<p>PyPy 和许多编译器, 解释器, 翻译器不同, 它不关心 Python 代码的词法分析和语法树. 因为它是用 Python 语言写的, 所以它直接利用 Python 语言的 <a href="http://docs.python.org/reference/datamodel.html">Code Object</a>. Code Object 是 Python 字节码的表示. 也就是说, PyPy <a href="http://codespeak.net/pypy/trunk/pypy/doc/architecture.html#id12">直接分析 Python 代码所对应的字节码</a>, 这些字节码即不是以字符形式也不是以某种二进制格式保存在文件中, 而在 Python 运行环境中.</p>
<p>越来越多的编程语言被设计成解释型, 但考虑到性能时, 几乎不约而同地想到转换成 C 语言. C 语言已经成为一个标杆, 任何编程语言都可以根据其距离 C 语言的远近来分类.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/269.html' rel='bookmark' title='Permanent Link: 开始学习 Python'>开始学习 Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/497.html' rel='bookmark' title='Permanent Link: 用脚本语言开发网游 &#8211; C整合Python'>用脚本语言开发网游 &#8211; C整合Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
<li><a href='http://www.ideawu.net/blog/archives/357.html' rel='bookmark' title='Permanent Link: MySQL 查询使用 Group By 的注意点'>MySQL 查询使用 Group By 的注意点</a></li>
<li><a href='http://www.ideawu.net/blog/archives/334.html' rel='bookmark' title='Permanent Link: 小巧且强大的集成开发环境(IDE) &#8211; Code::Blocks'>小巧且强大的集成开发环境(IDE) &#8211; Code::Blocks</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/499.html" title="PyPy &#8211; 吞下自己尾巴的小蟒蛇">PyPy &#8211; 吞下自己尾巴的小蟒蛇</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ideawu.net/blog/wp-content/uploads/2010/05/snake-eat-itself.jpg"><img src="http://www.ideawu.net/blog/wp-content/uploads/2010/05/snake-eat-itself.jpg" alt="" title="snake-eat-itself" width="128" height="128" class="alignright size-full wp-image-498" /></a></p>
<p><a href="http://www.pypy.org/">PyPy</a> 项目可能会颠覆老学究和初学者的逻辑, 因为 PyPy 用 Python 语言来实现 <a href="http://docs.python.org/reference/">Python</a> 语言, 就像一只小蟒蛇吞下自己的尾巴. 也许你没见过, 但它确实存在.</p>
<p>你可能会疑惑, 既然已经有了 Python, 那么为什么还用 Python 来实现 Python(PyPy)? 后者到底是什么东西?</p>
<p>其实, 这其中的逻辑并不复杂. 比如 C 语言, C 语言的第一个编译器肯定不是用 C 语言来编写的, 但之后, C 编译器(如 GCC)就没有理由不用 C 来编写了. 所以, 用 Python 语言编写, 并用已存在的 Python 编译器(解释器, 执行环境)来做一个实现 Python 语言并没有什么奇怪.</p>
<p><span id="more-499"></span><a href="http://www.pypy.org/"><img src="http://pypy.org/image/pypy-logo.png" alt="[pypy-logo]" /></a></p>
<p>简单地说, PyPy 是用 Python 语言写了一个工具, 将 Python 代码转成 C, .NET, Java 等语言和平台的代码. PHP 也有类似的项目 &#8211; <a href="http://www.hiphop-php.com/">HipHop-PHP</a>, 把 PHP 代码转成 C++ 代码.</p>
<p>为什么要将一种语言转成另一种语言? 首先是目标语言可能在性能(如C语言)和/或跨平台(如 .NET, Java)等方面具有优势. 其次, 在转换的过程, 可以进行代码优化或加入新技术, 比如 PyPy 应用的 Just-in-Time(JIT) 技术, 能让 Python (事实上是转换后的目标代码)的执行速度更快.</p>
<p>PyPy 和许多编译器, 解释器, 翻译器不同, 它不关心 Python 代码的词法分析和语法树. 因为它是用 Python 语言写的, 所以它直接利用 Python 语言的 <a href="http://docs.python.org/reference/datamodel.html">Code Object</a>. Code Object 是 Python 字节码的表示. 也就是说, PyPy <a href="http://codespeak.net/pypy/trunk/pypy/doc/architecture.html#id12">直接分析 Python 代码所对应的字节码</a>, 这些字节码即不是以字符形式也不是以某种二进制格式保存在文件中, 而在 Python 运行环境中.</p>
<p>越来越多的编程语言被设计成解释型, 但考虑到性能时, 几乎不约而同地想到转换成 C 语言. C 语言已经成为一个标杆, 任何编程语言都可以根据其距离 C 语言的远近来分类.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/269.html' rel='bookmark' title='Permanent Link: 开始学习 Python'>开始学习 Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/497.html' rel='bookmark' title='Permanent Link: 用脚本语言开发网游 &#8211; C整合Python'>用脚本语言开发网游 &#8211; C整合Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
<li><a href='http://www.ideawu.net/blog/archives/357.html' rel='bookmark' title='Permanent Link: MySQL 查询使用 Group By 的注意点'>MySQL 查询使用 Group By 的注意点</a></li>
<li><a href='http://www.ideawu.net/blog/archives/334.html' rel='bookmark' title='Permanent Link: 小巧且强大的集成开发环境(IDE) &#8211; Code::Blocks'>小巧且强大的集成开发环境(IDE) &#8211; Code::Blocks</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/499.html" title="PyPy &#8211; 吞下自己尾巴的小蟒蛇">PyPy &#8211; 吞下自己尾巴的小蟒蛇</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/499.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>用脚本语言开发网游 &#8211; C整合Python</title>
		<link>http://www.ideawu.net/blog/archives/497.html</link>
		<comments>http://www.ideawu.net/blog/archives/497.html#comments</comments>
		<pubDate>Fri, 07 May 2010 04:00:06 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.ideawu.net/blog/archives/497.html</guid>
		<description><![CDATA[<p>像因特网的Web系统一样, 几乎所有的大规模软件系统, 都会使用脚本语言. 在网络游戏服务器的开发中, 也会应用脚本语言. 游戏开发常用的脚本语言主要有: Python, Lua. 本文介绍在C语言中嵌入Python支持, C语言和Python语言通过API进行交互.</p>
<p>任何两种语言要整合, 首先要解决通信问题. C要和Python进行通信, 要进行数据结构转换, 把C的数据结构转为Python的对象, 和把Python对象转换为C数据结构.</p>
<p><span id="more-497"></span>下面对代码实例进行讲解, 代码忽略和错误处理.</p>
<pre>
#include &lt;python2.5/Python.h&gt;

void test1();
void test2();

PyObject *globals

int main(int argc, char **argv){
	PyObject *m, *obj1, *pobj;
	PyObject *request, *response;
	int i;

	Py_Initialize();
</pre>
<p>变量声明, 以及调用初始化函数 Py_Initialize().</p>
<pre>
	m = PyImport_AddModule("__main__");
	globals = PyModule_GetDict(m);
</pre>
<p>获取全局变量的字典表(哈希表). 在 Python 脚本中, 该字典表的键名就是全局变量的的名字. 例如, 全局变量字典表中有一项记录 &#8216;a&#8217; => &#8216;123&#8242;, 那么, 在 Python 脚本中, 变量 a 的值是 &#8216;123&#8242;. 该字典表就是 C 语言和 Python 语言进行通信的关键.</p>
<pre>
	request = PyDict_New();
	response = PyDict_New();

	PyDict_SetItemString(globals, "request", request);
	PyDict_SetItemString(globals, "response", response);

	obj1 = PyInt_FromLong(1);
	PyDict_SetItemString(request, "count", obj1);
</pre>
<p>在本代码例子中, 字典表 request 用于 C 向 Python 传递数据, response 用于 Python 脚本向 C 程序传递数据. 使用两个字典并不是必须的, 可以只用一个. request 中有一项键名为 &#8216;count&#8217; 的记录, 相当于向 Python 传递了一个名为 &#8216;count&#8217; 的参数.</p>
<pre>
	/* <a href="http://www.benegg.com/">http://www.benegg.com</a> */
	for(i = 0; i &lt; 2; i++){
		test1();
		pobj = PyDict_GetItemString(response, "code");
		printf("code: %s\n", PyString_AsString(pobj));

		test2();
		pobj = PyDict_GetItemString(response, "code");
		printf("code: %s\n", PyString_AsString(pobj));

		printf("---\n");
	}
</pre>
<p>Python 脚本中返回名为 &#8216;code&#8217; 的响应参数, 在 C 程序中将该参数的值打印出来.</p>
<pre>
	Py_DECREF(obj1);
	Py_DECREF(request);
	Py_DECREF(response);

out:
	Py_Finalize();
	return 0;
}
</pre>
<p>使用宏 Py_DECREF 减少对象的引用计数, 以便 Python 进行垃圾收集. 最后调用 Py_Finalize() 释放资源.</p>
<pre>
void test1(){
	FILE *fp;
	fp = fopen("benegg.com.py", "r");
	PyRun_SimpleFile(fp, filename);
	fclose(fp);
}
</pre>
<p>PyRun_SimpleFile() 函数执行一个 Python 脚本文件.</p>
<pre>
void test2(){
	FILE *fp;
	PyObject *co;
	char *buf;
	long size;

	fp = fopen("benegg.com.py", "r");
	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	rewind(fp);

	buf = malloc(size + 1);
	fread(buf, 1, size, fp);
	buf[size] = '\0';

	PyRun_SimpleString(buf);
</pre>
<p>因为 PyRun_SimpleFile() 每执行一次都要读取一次文件, 所以可以把文件内容读取到字符缓冲中, 然后多次执行 PyRun_SimpleString(), 避免磁盘 IO 造成性能消耗.</p>
<pre>
	co = Py_CompileString(buf, "benegg.com", Py_file_input);
	PyEval_EvalCode((PyCodeObject *)co, globals, globals);
</pre>
<p>不过, 虽然 PyRun_SimpleString() 避免了磁盘 IO, 然后还是会在每一次执行的时候解析文本代码. 这时, 可以把代码编译成一个 PyCodeObject 对象, 然后调用 PyEval_EvalCode() 执行, 避免了多次解析造成的性能消耗.</p>
<pre>
	Py_DECREF(co);
out:
	free(buf);
	fclose(fp);
}
</pre>
<p>Python 脚本代码如下:</p>
<pre>
print "test1 - %d" % request['count']
request['count'] += 1
response['code'] = "test" + str(request['count'])
</pre>
<p>编译 C 代码:</p>
<pre>
# http://www.benegg.com
gcc -g -Wall -o c test.c -L/usr/lib/python2.5/config -lpython2.5
</pre>
<p>注意, 将路径改为你机器上的实际路径. 执行 ./c, 可以看到, 执行的结果是:</p>
<pre>
test1 - 1
code: test2
test1 - 2
test1 - 3
code: test4
---
test1 - 4
code: test5
test1 - 5
test1 - 6
code: test7
</pre>
<p>原发在: <a href="http://www.benegg.com/game/archives/51.html">http://www.benegg.com/game/archives/51.html</a></p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/499.html' rel='bookmark' title='Permanent Link: PyPy &#8211; 吞下自己尾巴的小蟒蛇'>PyPy &#8211; 吞下自己尾巴的小蟒蛇</a></li>
<li><a href='http://www.ideawu.net/blog/archives/357.html' rel='bookmark' title='Permanent Link: MySQL 查询使用 Group By 的注意点'>MySQL 查询使用 Group By 的注意点</a></li>
<li><a href='http://www.ideawu.net/blog/archives/269.html' rel='bookmark' title='Permanent Link: 开始学习 Python'>开始学习 Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/264.html' rel='bookmark' title='Permanent Link: 通过 HTTP POST 发送二进制数据'>通过 HTTP POST 发送二进制数据</a></li>
<li><a href='http://www.ideawu.net/blog/archives/533.html' rel='bookmark' title='Permanent Link: 经典的&#8221;服务器最多65536个连接&#8221;误解'>经典的&#8221;服务器最多65536个连接&#8221;误解</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/497.html" title="用脚本语言开发网游 &#8211; C整合Python">用脚本语言开发网游 &#8211; C整合Python</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<p>像因特网的Web系统一样, 几乎所有的大规模软件系统, 都会使用脚本语言. 在网络游戏服务器的开发中, 也会应用脚本语言. 游戏开发常用的脚本语言主要有: Python, Lua. 本文介绍在C语言中嵌入Python支持, C语言和Python语言通过API进行交互.</p>
<p>任何两种语言要整合, 首先要解决通信问题. C要和Python进行通信, 要进行数据结构转换, 把C的数据结构转为Python的对象, 和把Python对象转换为C数据结构.</p>
<p><span id="more-497"></span>下面对代码实例进行讲解, 代码忽略和错误处理.</p>
<pre>
#include &lt;python2.5/Python.h&gt;

void test1();
void test2();

PyObject *globals

int main(int argc, char **argv){
	PyObject *m, *obj1, *pobj;
	PyObject *request, *response;
	int i;

	Py_Initialize();
</pre>
<p>变量声明, 以及调用初始化函数 Py_Initialize().</p>
<pre>
	m = PyImport_AddModule("__main__");
	globals = PyModule_GetDict(m);
</pre>
<p>获取全局变量的字典表(哈希表). 在 Python 脚本中, 该字典表的键名就是全局变量的的名字. 例如, 全局变量字典表中有一项记录 &#8216;a&#8217; => &#8216;123&#8242;, 那么, 在 Python 脚本中, 变量 a 的值是 &#8216;123&#8242;. 该字典表就是 C 语言和 Python 语言进行通信的关键.</p>
<pre>
	request = PyDict_New();
	response = PyDict_New();

	PyDict_SetItemString(globals, "request", request);
	PyDict_SetItemString(globals, "response", response);

	obj1 = PyInt_FromLong(1);
	PyDict_SetItemString(request, "count", obj1);
</pre>
<p>在本代码例子中, 字典表 request 用于 C 向 Python 传递数据, response 用于 Python 脚本向 C 程序传递数据. 使用两个字典并不是必须的, 可以只用一个. request 中有一项键名为 &#8216;count&#8217; 的记录, 相当于向 Python 传递了一个名为 &#8216;count&#8217; 的参数.</p>
<pre>
	/* <a href="http://www.benegg.com/">http://www.benegg.com</a> */
	for(i = 0; i &lt; 2; i++){
		test1();
		pobj = PyDict_GetItemString(response, "code");
		printf("code: %s\n", PyString_AsString(pobj));

		test2();
		pobj = PyDict_GetItemString(response, "code");
		printf("code: %s\n", PyString_AsString(pobj));

		printf("---\n");
	}
</pre>
<p>Python 脚本中返回名为 &#8216;code&#8217; 的响应参数, 在 C 程序中将该参数的值打印出来.</p>
<pre>
	Py_DECREF(obj1);
	Py_DECREF(request);
	Py_DECREF(response);

out:
	Py_Finalize();
	return 0;
}
</pre>
<p>使用宏 Py_DECREF 减少对象的引用计数, 以便 Python 进行垃圾收集. 最后调用 Py_Finalize() 释放资源.</p>
<pre>
void test1(){
	FILE *fp;
	fp = fopen("benegg.com.py", "r");
	PyRun_SimpleFile(fp, filename);
	fclose(fp);
}
</pre>
<p>PyRun_SimpleFile() 函数执行一个 Python 脚本文件.</p>
<pre>
void test2(){
	FILE *fp;
	PyObject *co;
	char *buf;
	long size;

	fp = fopen("benegg.com.py", "r");
	fseek(fp, 0, SEEK_END);
	size = ftell(fp);
	rewind(fp);

	buf = malloc(size + 1);
	fread(buf, 1, size, fp);
	buf[size] = '\0';

	PyRun_SimpleString(buf);
</pre>
<p>因为 PyRun_SimpleFile() 每执行一次都要读取一次文件, 所以可以把文件内容读取到字符缓冲中, 然后多次执行 PyRun_SimpleString(), 避免磁盘 IO 造成性能消耗.</p>
<pre>
	co = Py_CompileString(buf, "benegg.com", Py_file_input);
	PyEval_EvalCode((PyCodeObject *)co, globals, globals);
</pre>
<p>不过, 虽然 PyRun_SimpleString() 避免了磁盘 IO, 然后还是会在每一次执行的时候解析文本代码. 这时, 可以把代码编译成一个 PyCodeObject 对象, 然后调用 PyEval_EvalCode() 执行, 避免了多次解析造成的性能消耗.</p>
<pre>
	Py_DECREF(co);
out:
	free(buf);
	fclose(fp);
}
</pre>
<p>Python 脚本代码如下:</p>
<pre>
print "test1 - %d" % request['count']
request['count'] += 1
response['code'] = "test" + str(request['count'])
</pre>
<p>编译 C 代码:</p>
<pre>
# http://www.benegg.com
gcc -g -Wall -o c test.c -L/usr/lib/python2.5/config -lpython2.5
</pre>
<p>注意, 将路径改为你机器上的实际路径. 执行 ./c, 可以看到, 执行的结果是:</p>
<pre>
test1 - 1
code: test2
test1 - 2
test1 - 3
code: test4
---
test1 - 4
code: test5
test1 - 5
test1 - 6
code: test7
</pre>
<p>原发在: <a href="http://www.benegg.com/game/archives/51.html">http://www.benegg.com/game/archives/51.html</a></p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/499.html' rel='bookmark' title='Permanent Link: PyPy &#8211; 吞下自己尾巴的小蟒蛇'>PyPy &#8211; 吞下自己尾巴的小蟒蛇</a></li>
<li><a href='http://www.ideawu.net/blog/archives/357.html' rel='bookmark' title='Permanent Link: MySQL 查询使用 Group By 的注意点'>MySQL 查询使用 Group By 的注意点</a></li>
<li><a href='http://www.ideawu.net/blog/archives/269.html' rel='bookmark' title='Permanent Link: 开始学习 Python'>开始学习 Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/264.html' rel='bookmark' title='Permanent Link: 通过 HTTP POST 发送二进制数据'>通过 HTTP POST 发送二进制数据</a></li>
<li><a href='http://www.ideawu.net/blog/archives/533.html' rel='bookmark' title='Permanent Link: 经典的&#8221;服务器最多65536个连接&#8221;误解'>经典的&#8221;服务器最多65536个连接&#8221;误解</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/497.html" title="用脚本语言开发网游 &#8211; C整合Python">用脚本语言开发网游 &#8211; C整合Python</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/497.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用Python POST任意的HTTP数据以及使用Cookie</title>
		<link>http://www.ideawu.net/blog/archives/270.html</link>
		<comments>http://www.ideawu.net/blog/archives/270.html#comments</comments>
		<pubDate>Thu, 30 Aug 2007 08:52:06 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>如果不使用Cookie, 发送HTTP POST非常简单:</p>
<pre>
import urllib2, urllib

data = {'name' : 'www', 'password' : '123456'}
f = urllib2.urlopen(
        url     = '<a href="http://www.ideawu.net/">http://www.ideawu.net/</a>',
        data    = urllib.urlencode(data)
		)
print f.read()
</pre>
<p>当使用Cookie时, 代码变得有些复杂:</p>
<pre>import urllib2

cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)

f = opener.open('<a href="http://www.ideawu.net/">http://www.ideawu.net/</a>?act=login&amp;name=user01')

data = '&lt;root&gt;Hello&lt;/root&gt;'
request = urllib2.Request(
        url     = '<a href="http://www.ideawu.net/">http://www.ideawu.net/</a>?act=send',
        headers = {'Content-Type' : 'text/xml'},
        data    = data)

opener.open(request)
</pre>
<p> 第一次 open() 是进行登录. 服务器返回的 Cookie 被自动保存在 cookies 中, 被用在后来的请求. </p>
<p> 第二次 open() 用 POST 方法向服务器发送了 Content-Type=text/xml 的数据. 如果你不创建一个 Request, 而是直接使用 urlopen() 方法, Python 强制把 Content-Type 改为 application/x-www-form-urlencoded. </p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/611.html' rel='bookmark' title='Permanent Link: 强大的纯JS数据图工具-flot'>强大的纯JS数据图工具-flot</a></li>
<li><a href='http://www.ideawu.net/blog/archives/399.html' rel='bookmark' title='Permanent Link: JavaScript+jQuery两栏选择控件'>JavaScript+jQuery两栏选择控件</a></li>
<li><a href='http://www.ideawu.net/blog/archives/264.html' rel='bookmark' title='Permanent Link: 通过 HTTP POST 发送二进制数据'>通过 HTTP POST 发送二进制数据</a></li>
<li><a href='http://www.ideawu.net/blog/archives/25.html' rel='bookmark' title='Permanent Link: JSP中文乱码解决之道'>JSP中文乱码解决之道</a></li>
<li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/270.html" title="使用Python POST任意的HTTP数据以及使用Cookie">使用Python POST任意的HTTP数据以及使用Cookie</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<p>如果不使用Cookie, 发送HTTP POST非常简单:</p>
<pre>
import urllib2, urllib

data = {'name' : 'www', 'password' : '123456'}
f = urllib2.urlopen(
        url     = '<a href="http://www.ideawu.net/">http://www.ideawu.net/</a>',
        data    = urllib.urlencode(data)
		)
print f.read()
</pre>
<p>当使用Cookie时, 代码变得有些复杂:</p>
<pre>import urllib2

cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)

f = opener.open('<a href="http://www.ideawu.net/">http://www.ideawu.net/</a>?act=login&amp;name=user01')

data = '&lt;root&gt;Hello&lt;/root&gt;'
request = urllib2.Request(
        url     = '<a href="http://www.ideawu.net/">http://www.ideawu.net/</a>?act=send',
        headers = {'Content-Type' : 'text/xml'},
        data    = data)

opener.open(request)
</pre>
<p> 第一次 open() 是进行登录. 服务器返回的 Cookie 被自动保存在 cookies 中, 被用在后来的请求. </p>
<p> 第二次 open() 用 POST 方法向服务器发送了 Content-Type=text/xml 的数据. 如果你不创建一个 Request, 而是直接使用 urlopen() 方法, Python 强制把 Content-Type 改为 application/x-www-form-urlencoded. </p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/611.html' rel='bookmark' title='Permanent Link: 强大的纯JS数据图工具-flot'>强大的纯JS数据图工具-flot</a></li>
<li><a href='http://www.ideawu.net/blog/archives/399.html' rel='bookmark' title='Permanent Link: JavaScript+jQuery两栏选择控件'>JavaScript+jQuery两栏选择控件</a></li>
<li><a href='http://www.ideawu.net/blog/archives/264.html' rel='bookmark' title='Permanent Link: 通过 HTTP POST 发送二进制数据'>通过 HTTP POST 发送二进制数据</a></li>
<li><a href='http://www.ideawu.net/blog/archives/25.html' rel='bookmark' title='Permanent Link: JSP中文乱码解决之道'>JSP中文乱码解决之道</a></li>
<li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/270.html" title="使用Python POST任意的HTTP数据以及使用Cookie">使用Python POST任意的HTTP数据以及使用Cookie</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/270.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>开始学习 Python</title>
		<link>http://www.ideawu.net/blog/archives/269.html</link>
		<comments>http://www.ideawu.net/blog/archives/269.html#comments</comments>
		<pubDate>Thu, 30 Aug 2007 02:41:44 +0000</pubDate>
		<dc:creator>ideawu</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<p>最近需要一种脚本语言做快速的原型开发, 因为类似 C/C++, Java, C# 之类的语言调试很困难. 特别是 Java 和 C#, 开发环境庞大, 一运行, 别的事就别想做了. 我希望找到一种只需要文本编辑器就可以开发的语言. 于是寻找:</p>
<p>首先想到是 PHP, 因为我比较熟悉. 不过, PHP 不支持线程, 而且在 Web 之外的应用不强大, 所以排除.</p>
<p>也没别的了, 就考虑 Python 吧. 首先, 必须对 HTTP 支持良好. 经过一段时间的试用, 中间一些失望, 感觉 Python 能很符合我的需要. Python 的文档缺少像 Java API Doc 那样的结构. Python 的类文档结构不是很明显, 甚至方法和属性列表不完整, 可能是 Python 的哲学吧. 不过, 我更希望类的构造函数文档和方法以及属性文档放在同一页.</p>
<p>无论使用 Python 做快速的原型开发还是最终的产品, 我觉得还是可以的.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
<li><a href='http://www.ideawu.net/blog/archives/499.html' rel='bookmark' title='Permanent Link: PyPy &#8211; 吞下自己尾巴的小蟒蛇'>PyPy &#8211; 吞下自己尾巴的小蟒蛇</a></li>
<li><a href='http://www.ideawu.net/blog/archives/624.html' rel='bookmark' title='Permanent Link: Python logging 标准配置'>Python logging 标准配置</a></li>
<li><a href='http://www.ideawu.net/blog/archives/497.html' rel='bookmark' title='Permanent Link: 用脚本语言开发网游 &#8211; C整合Python'>用脚本语言开发网游 &#8211; C整合Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/21.html' rel='bookmark' title='Permanent Link: 教你如何得到j2sdk的文档'>教你如何得到j2sdk的文档</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/269.html" title="开始学习 Python">开始学习 Python</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></description>
			<content:encoded><![CDATA[<p>最近需要一种脚本语言做快速的原型开发, 因为类似 C/C++, Java, C# 之类的语言调试很困难. 特别是 Java 和 C#, 开发环境庞大, 一运行, 别的事就别想做了. 我希望找到一种只需要文本编辑器就可以开发的语言. 于是寻找:</p>
<p>首先想到是 PHP, 因为我比较熟悉. 不过, PHP 不支持线程, 而且在 Web 之外的应用不强大, 所以排除.</p>
<p>也没别的了, 就考虑 Python 吧. 首先, 必须对 HTTP 支持良好. 经过一段时间的试用, 中间一些失望, 感觉 Python 能很符合我的需要. Python 的文档缺少像 Java API Doc 那样的结构. Python 的类文档结构不是很明显, 甚至方法和属性列表不完整, 可能是 Python 的哲学吧. 不过, 我更希望类的构造函数文档和方法以及属性文档放在同一页.</p>
<p>无论使用 Python 做快速的原型开发还是最终的产品, 我觉得还是可以的.</p>


<h3>Related posts:</h3><ol><li><a href='http://www.ideawu.net/blog/archives/508.html' rel='bookmark' title='Permanent Link: Windows Python select标准输入输出'>Windows Python select标准输入输出</a></li>
<li><a href='http://www.ideawu.net/blog/archives/499.html' rel='bookmark' title='Permanent Link: PyPy &#8211; 吞下自己尾巴的小蟒蛇'>PyPy &#8211; 吞下自己尾巴的小蟒蛇</a></li>
<li><a href='http://www.ideawu.net/blog/archives/624.html' rel='bookmark' title='Permanent Link: Python logging 标准配置'>Python logging 标准配置</a></li>
<li><a href='http://www.ideawu.net/blog/archives/497.html' rel='bookmark' title='Permanent Link: 用脚本语言开发网游 &#8211; C整合Python'>用脚本语言开发网游 &#8211; C整合Python</a></li>
<li><a href='http://www.ideawu.net/blog/archives/21.html' rel='bookmark' title='Permanent Link: 教你如何得到j2sdk的文档'>教你如何得到j2sdk的文档</a></li>
</ol><div><p><img src="http://www.ideawu.net/favicon.ico" /> 你现在看的文章是: <a href="http://www.ideawu.net/blog/archives/269.html" title="开始学习 Python">开始学习 Python</a></p>

<div>
	<a href="http://www.benegg.com/linode-ad.php">
		Linode VPS - 美国虚拟主机
	</a>
	|
	<a href="http://www.udpwork.com/">
		IT牛人博客聚合网站
	</a>
</div></div>]]></content:encoded>
			<wfw:commentRss>http://www.ideawu.net/blog/archives/269.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

