Python 多线程 XML RPC的实现

python 中的SimpleXMLRPCServer只能支持单线程访问对象.如果想使用多线程的 SimpleXMLRPCServer.最好的办法就是继承ThreadMixIn.简单吧:)下面是代码
Continue reading Python 多线程 XML RPC的实现 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

python国际化(i18n)和中英文切换

Python通过gettext模块支持国际化(i18n),可以实现程序的多语言界面的支持,下面是我的多语言支持实现:

1.         在python安装目录下的./Tools/i18n/(windows下例 D:\Program Files\Python25\Tools\i18n)目录中找到pygettext.py运行之,生成翻译文件模版messages.pot,内容大概是这个样子:

 

Continue reading python国际化(i18n)和中英文切换 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

glade+pygtk 试用札记

   由于用python写程序,我已经考察过了好几种python的界面编写包,默认的tcl/tk,wxWindow,近来又试用pygtk。感觉用
pygtk是最顺手的,大约是因为我不熟悉c++而更熟悉c和callback吧。在加上glade编辑界面非常迅速方便,我更喜欢这个python+
pygtk+glade的组合了。
   gtk的大名相信不用我多介绍,gnome就是用它开发的,pygtk是gtk的python接口封装(反正就是在python中调用gtk,具体名称是
什么我也没弄清楚)。glade是gtk的界面编辑工具,不象我们在win下熟悉的vb,c++builder等IDE,glade只管生产界面和产生相
关的代码,至于编译和代码编写,你还需要vim,gcc等其它工具。
Continue reading glade+pygtk 试用札记 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Universal Encoding Detector

http://chardet.feedparser.org/
http://chardet.feedparser.org/docs/how-it-works.html
参考:http://www.mozilla.org/projects/intl/UniversalCharsetDetection.html

Basic usage

The easiest way to use the Universal Encoding Detector library is with the detect function.

Continue reading Universal Encoding Detector - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

URL 调度程序

对高质量的 WEB 应用程序来说, 有一个干净优雅的 URL 调度机制是至关重要的. Django 允许你根据需要设计 URLs ,没有任何框架层的限制.

不需要 .php 或 .cgi 扩展名, 也没有象 0,2097,1-1-1928,00 那样的丑陋东西.

参阅 WWW 的缔造者 Tim Berners-Lee 所写的 Cool URIs don’t change, 这篇文章的主题就是为什么 URL 应该是干净并且便于使用的.

1   概述

要为一个应用程序设计 URLs, 要生成一个称为 URLconf (URL 配置) 的非正式的 Python 模块. 该模块为纯 Python 代码, 它的作用就是在 URL 模式(简单的正则表达式)及 Python 回调函数( 你的 views) 之间建立映射.

这个映射根本需要可以很短,也可以很长. 它能够引用其它的映射. 由于是纯 Python 代码, 就有能力动态的创建这种映射.

Continue reading URL 调度程序 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

python range()函数的用法

在以往用range函数的时候从未深入的了解过,只是简单的这样用,而从未去想其他的

>>> range(1,5) #两个参数的,从1到5
[1, 2, 3, 4]
>>> range(1,5,2) #三个参数的,从1到5,间隔数字为2,所以显示奇数
[1, 3]
>>> range(5) #一个参数的,默认start是从0开始,end是5
[0, 1, 2, 3, 4]

今天看《python核心编程》第二版中,在讲切片时,作者举了一个例子:“有这么一个问题:有一个字符串,我们想通过一个循环按照这样的形式显示它:每次都把位于最后的一个字符砍掉”,这个例子虽然很小,也很简单
Continue reading python range()函数的用法 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Python 3.1.1 RC发布

Python是一门跨平台的脚本语言,Python规定了一个Python语法规则,实现了Python语法的解释程序就成为了Python的解释器,我 们用的比较多的是C版本的Python,也就是使用C语言实现的Python解释器,除此之外还有使用Java实现的Jython和使用.NET实现的 IronPython,这些实现可以使Python用户充分利用己有的Java及.NET资源.

The Python 3.1.1 release candidate was released on August 13th, 2009.

Python 3.1 is a continuation of the work started by Python 3.0, the new backwards-incompatible series of Python. Improvements in this release include:
Continue reading Python 3.1.1 RC发布 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

py2exe,生成可执行文件.

py2exe,用python脚本生成可执行文件
Py2exe 官网:
http://www.py2exe.org/

先要写一个setup的脚本,格式如下:

#!/usr/bin/env python

from distutils.core import setup

setup(name=’Distutils’,
      version=’1.0′,
      description=’Python Distribution Utilities’,
      author=’Greg Ward’,
      author_email=’gward@python.net‘,
      url=’http://www.python.org/sigs/distutils-sig/’,
      packages=['distutils', 'distutils.command'],
     )
假设你准备转换的脚本保存为myscript.py 

然后写setup.py,内容如下:

# setup.py
from distutils.core import setup
import py2exe

setup(console=["myscript.py"])
如果你想要在你的py程序运行时候不在别后显示讨厌的shell黑框,你只要把console=["myscript.py"] 替换成windows=["myscript.py"].

然后在shell当中运行如下内容:

python setup.py py2exe
OK,exe程序轻松搞定。

来点复杂的:
如果你想把你的py程序注册成为windows nt的服务程序。只要把脚本修改成如下就可以了:

# setup.py
from distutils.core import setup
import py2exe

setup(service=["MyService"]) http://hi.baidu.com/webtalk/blog/item/2f0d0708f01572d163d9863c.html

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis

Python 字符串方法详解

在编程中,几乎90% 以上的代码都是关于整数或字符串操作,所以与整数一样,Python
的字符串实现也使用了许多拿优化技术,使得字符串的性能达到极致。与 C++ 标准库(STL)中的 std::string 不同,python
字符串集合了许多字符串相关的算法,以方法成员的方式提供接口,使用起来非常方便。 字符串方法大约有几十个,这些方法可以分为如下几类(根据 manuals 整理):

Continue reading Python 字符串方法详解 - 全文阅读

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • MySpace
  • RSS
  • Slashdot
  • Technorati
  • TwitThis
 Page 1 of 2  1  2 »

Contact us

Admin: Bryan Wu