ITeye博客

2007 年文章归档

共 43 篇文章

实现一个 django 的 url dispatcher

心血来潮,实现了一个 django 的 url dispatcher,比想象中简单多了。 http://djangodispatcher.googlecode.com/svn/trunk/mapper.py http://djangodispatcher.googlecode.com/svn/trunk/test.py 实际实现功能的代码才2、30行,功能基本完整,包括分层次的url配置,和发生异常时帮助调试用的一些信息。 PS:发现最近爱上了 Test Driven.

2007-06-25 17:22 · django

如何在醉酒的情况下编写正确的程序

答案很简单:Test Driven。 哈哈,这个( http://code.google.com/p/pylifegame/ )就是好例子! 醉了,不多说了,自己看去,我要睡觉去了,嗯 ...

2007-06-22 09:12 · python

Faint! 和我同名的编辑器

Yi Yi is a text editor written and extensible in Haskell. The goal of Yi is to provide a flexible, powerful and correct editor core dynamically scriptable in Haskell.

2007-06-20 04:18 · others

原来 pickle 这么有意思

Pickle: An interesting stack language 原来 pickle 本身就是就是一个微型的基于栈的语言,呵呵,有点意思。 研究一下 pickle.py 和 pickletools.py ,可以看到更细节的东西。

2007-06-20 03:31 · pickle

翻译了这篇文章

Python 3000 进度报告 也可以从 guido 的中文 blog 看到: http://blog.csdn.net/gvanrossum/archive/2007/06/20/1658829.aspx

2007-06-20 03:27 · python3000

Python 3000 Status Update (Long!)

Python 3000 Status Update (Long!) by Guido van Rossum """ Summary Here's a long-awaited update on where the Python 3000 project stands. We're looking at a modest two months of schedule slip, and many exciting new features. I'll be presenting this in person several times over the next two months. """

2007-06-19 08:41 · python3000

老子毕业了

http://picasaweb.google.com/yi.codeplayer/070608

2007-06-08 16:32 · others

SQLAlchemy Examples

看 SQLAlchemy 自带的 zblog 的例子,可以看到 SQLAlchemy 一些非常有用的特性。 文章相关评论数统计 比如显示文章列表的同时我们希望获得相关文章的评论数,如果是用 django 那就只能放弃 ORM 的好处自己去执行 sql 语句了,否则就只会导致 n+1 条 SQL 语句的执行。 在 SQLAlchemy 中你可以把任意的 select 语句映射到一个 class ,这样就可以用一条 SQL 语句搞定,还能获得 ORM 的好处,下面是原封不动拷过来的代码(只调整了下格式): # Post mapper, these are posts within a blog.…

2007-06-02 18:47 · sqlalchemy

multitask and Hive

multitask multitask allows Python programs to use generators (aka coroutines) to perform cooperative multitasking and asynchronous I/O. Applications written using multitask consist of a set of cooperating tasks that yield to a shared task manager whenever they perform a (potentially) blocking opera…

2007-05-30 04:40 · stackless

Polymorphic Associations in Rails

Polymorphic Associations with SQLAlchemy SQLAlchemy 老大 展示怎么用 sqlalchemy 实现 rails 的 Polymorphic Associations 顺便看了下 Rails 所谓 Polymorphic Associations 的介绍,才发现其实就是我很早就 介绍过 的 django 的 content-type app 所干的事情,app 就是插件的意思。

2007-05-30 04:28 · sqlalchemy

Python and vim: Two great tastes that go great together

Python and vim: Two great tastes that go great together 用 python 扩展 vim ,想法倒是不新,不过第一次看到 tutotial 。 记得 tocer 说过要用 python 写个 vim 库的,不知道有没有进展哈,呵呵。

2007-05-26 08:29 · python

Evolution of a Python programmer

http://dis.4chan.org/read/prog/1180084983/ 哈哈,有点意思,再加一个: Python 2.5 programmer: def fact(x): return x * fact(x - 1) if x > 1 else 1 print fact(6)

2007-05-26 07:51 · python

Elixir Examples

有的时候在 blog 里写 wiki,有的时候在 wiki 里写 blog,有的时候在 blog 里发在 wiki 里写的 blog ;-)

2007-05-21 18:57

多重继承真是好哇

写 model 的时候发现有些东西在重复,第一反应就是写个基类,把这些重复的东西拿出来,然而 Model 类之间继承却不是那么方便的,应该会影响到 ORM 的行为。 怎么办呢?幸好 python 有多重继承。 下面就是项目中做这些重复事情的类: class ModelMixin(object): def save(self): if not self.id: # creation time if hasattr(self, 'pubdate'): self.pubdate = datetime.now() if hasattr(self, 'pubtime'): self.pubtime =…

2007-05-21 18:30 · django

newforms 太好用了

建一个项目 newformstutorials ,建一个 app blog ,在 blog 的 models 中定义个: class Article(models.Model): title = models.CharField(u'标题', maxlength=255) author = models.CharField(u'作者', maxlength=20) hits = models.IntegerField(u'点击数', default=0, editable=False) content = models.TextField(u'内容') 配置好数据库,把 newformstu…

2007-05-21 17:40 · django

django newforms admin

又用 django 做了个项目,因为主要都是后台的东西,所以决定启用 django 的 newforms admin 分支 !(不过这里我不是推荐大家现在就开始用 newforms admin 分支,如果没有把握,最好是抱着玩玩的态度先,我在开发过程中就改掉它好几个bug) newforms admin 分支是用 newforms 来重构 admin 模块,也顺便改变了一些设计决策,大大增强了 admin 的可定制性。首先 newforms 的应用,成功分离了 db field、form field、widget 三个部分,db field 属于 ORM ,主要负责 model 相关的事务,…

2007-05-21 16:52 · django

python3000与接口

""" 要编写复杂软件又不至于一败涂地的唯一方法就是用定义清晰的接口把若干简单模块组合起来。 """ 抽象的说,其实接口、契约、协议、界面等等概念说的差不多都是一个意思。 作为如此流行的被大规模使用的语言,python 一直没有这么个东西的标准实现,实在是一种遗憾,当然第三方的实现 zope.interface 其实早就在 zope 和 twisted 中大量应用了。 python 3000 中正在讨论的: pep 3119 Introducing Abstract Base Classes ; pep 3124 Overloading, Generic Functions, Interfa…

2007-05-15 14:35 · python3000

好久没写blog了

好久没写 blog 了,现在毕业论文终于敲定,可以长舒一口气 ;-) 写论文的时候,rst 可真是帮我不少忙,不过学校规定得交 doc 的版本,包括论文的格式什么的都是针对 msword 来说的,只好用 rst 生成 html ,然后拷贝到 msword。看到同学直接在 msword 里写论文,最后再痛苦地调整格式,窃喜 ;-) 继续我们可爱的python的写作,不过写到现在感觉自己还是不习惯写入门的东西,总是不自觉地想用最简洁的语言把所有东西都说出来(不过这倒符合python的哲学 = =" ),只好努力压下许多 python 的好东东了。

2007-05-15 13:48 · others

新的 pep !

虽然我发晚了一点,但还是很值得一看的 PEP ;-)

2007-04-02 07:31 · others

trying out PyPy

对 pypy 的简单试验,惊叹其优化的智能!

2007-03-30 08:01 · pypy