Blog信息 |
blog名称: 日志总数:1304 评论数量:2242 留言数量:5 访问次数:7595867 建立时间:2006年5月29日 |

| |
[Python]使用 nose 測試工具簡單做測試 软件技术
lhwork 发表于 2007/2/25 12:03:52 |
三步驟使用 nose 開始測試
1. 安裝或更新 nose # easy_install -U nose
沒用過 easy_install ? 你該開始試著用了!
2. 撰寫測試用例 (test case) 打開一個新的 python 檔案, 我們統一在這個新檔案裡寫測試用例
將要測試的模組匯入:
file something.py 的內容: class Hello: def __init__(self): self.template = " |
|
[Python]中文字符串的截取 软件技术
lhwork 发表于 2007/2/25 11:01:13 |
def subString(s, length): us = unicode(s, 'utf-8') gs = us.encode('gb2312') n = int(length) t = gs[:n] while True: try: &n |
|
[Python]feedparser 1 软件技术
lhwork 发表于 2007/2/16 12:15:39 |
feedparser,是 Python 的一个通用聚合解析模块。它可以处理RSS 0.90、Netscape RSS
0.91、Userland RSS 0.91、RSS 0.92、RSS 0.93、RSS 0.94、RSS 1.0、RSS 2.0、Atom
0.3、Atom 1.0 以及 CDF 聚合。它还可以解析几种流行的扩展,包括 Dublin Core 和 Apple 的 iTunes 扩展。例子1:从 URL 解析远程文件>>> import feedparser >>> d = feedparser.parse( ... 'http://feedparser.org/docs/examples/atom10.xml' ... ) >>> d['feed']['title'] u'Sample Feed' 例子2:解析本地文件>>> import feedparser >>& |
|
[Python]收集的一些python程序,实用并且有趣  软件技术
lhwork 发表于 2007/2/7 9:06:29 |
这几天有空就做做python,下面是我收集的一些代码,大家可以看看,python真的很有有趣!
1。生成随机数 import random #这个是注释,引入模块 rnd = random.randint(1,500)#生成1-500之间的随机数
2。读文件
f = open("c://1.txt","r") lines = f.readlines()#读取全部内容 & |
|
[Python]web.py 0.2 教程 软件技术
lhwork 发表于 2007/2/6 16:42:31 |
开始
So you know Python and want to make a website. web.py provides the code to make that easy.既然你已经了解了 Python 并且想做一个网站。web.py 提供了代码使这个过程变得简单。
If you want to do the whole tutorial, you'll need to have installed Python, web.py, flup, p |
|
[Python]web.py 进阶2,连接 MySQL 数据库,以及其它的一些内容 软件技术
lhwork 发表于 2007/2/6 16:38:18 |
第一部分在这里
申明一点,这里的例子都是基于 web.py 0.2 版本的。现在网上的 web.py 中文教程是基于 0.1 的,如果你看到的文章一开始说要安装什么 Cheetah,那肯定不适用现在的情况了。
首先说的是 Python 连 MySQL,以及 UTF-8 字符集的事情。我这里假设你的应用是纯 UTF-8 的,而且使用 MySQL 4.1 以上的版本。
Python for MySQL 的连接扩展在 mysql-python,Debian Sarge 的包里面是 1.2.1c2 版,是不支持 4.1 的 Charset 特性的,最新的 1.2.1_p2 版支持的很好,只不过从这个版本开始必须依赖 Python2.4 了。
当使用 mysql-python connect()的时候有两个重要参数,chars |
|
[Python]Apache 2.2 + web.py + RoR 软件技术
lhwork 发表于 2007/2/6 16:37:08 |
1. mod_python 非常不主流,所有 Python 的 Web 框架都内置一个 HTTP Server 的实现(在 Python 世界里这样做太简单了),web.py 还包括了 FastCGI/SCGI 的支持。RoR 也同样通过 mongrel 提供了 web server 支撑。
2. lighttpd 支持反向代理,也支持 FastCGI,再加上它确实够轻,性能也不错,而且用 apache httpd 不够酷,于是它成了新潮 web hacker 们的最爱。
3. 其实我很有理由使用 lighttpd,因为我的内存只有 128M。但我想通过 http 端口来跑 svn,没办法,只有用 apache。编译的时候加上 rewrite/proxy 的支持./configure --prefix=/usr/local/apache2 --enable-so -enable-ssl \
--enable-rewrite --enable-proxy --enable-proxy-http
mo |
|
[Python]web.py 进阶例程 软件技术
lhwork 发表于 2007/2/6 16:34:18 |
web.py 的首页提供了一个 13 行的例子来演示如何开始一个应用,但其网站上似乎就没有别的更进一步的例子了。这两天简短学习了一下,写一个进阶例程。包括:读取 GET/POST 变量,以及模板的使用。
#!/usr/bin/python
import web
urls = (
'/sample', 'sample',
'/( |
|
[Python]web.py templating system (codename: templetor) 软件技术
lhwork 发表于 2007/2/6 16:33:50 |
There are almost as many Python templating systems as there are web frameworks (and, indeed, it seems like many templating systems are adopting web framework-like features), so it is with some trepidation that I work on a new one. Sadly, again I find that my requirements are met by nothing else:
The templating system has to look decent. No <%#foo#%> crud.
Reuse Python terms and semantics as much as possible.
Expressive enough to do real c |
|
|