Bottle推介~简洁的直观对比

Bottle 项目推介:义乌小额批发搜索引擎 - Bottle - python.cn(jobs, news) 引发...

老光

老光 <[email protected]>
发件人当地时间 发送时间 08:57 (GMT+08:00)。发送地当前时间:上午9:43。 ✆
回复      [email protected]
发送至     [email protected]
日期      2010年11月9日 上午8:57
主题      Re: [CPyUG] Re: Bottle 项目推介:义乌小额批发搜索引擎

忍不住回一句,到底什么叫简洁?

   1 from bottle import Bottle, run, mako_view, request
   2 
   3 myapp = Bottle()
   4 
   5 @myapp.get('/hello/:name/:count#\\d+#')
   6 @mako_view('hello')
   7 def hello(name, count):
   8     ip = request.environ.get('REMOTE_ADDR')
   9     return dict(n=name, c=int(count), ip=ip)
  10 
  11 run(app=myapp)

我凡是看到大多数框架,看到这种一个简单的"hello world"要写七八行以上的,就觉得头疼;而且比如上面的一段代码,一眼看完后,不知道最后执行的run(app=myapp),与hello是怎么关联上的.

我们看Karrigell.py的hello示例,理解什么叫简洁:

   1 print "Hello world"

我只能够接受到eurasia的hello例子,虽然他行数也很多:

   1 #!/usr/bin/python2.5
   2 from eurasia import config, mainloop
   3 def handler(httpfile):
   4     httpfile['Content-Type'] = 'text/html'
   5         httpfile.write('<html>hello world!</html>')
   6     httpfile.close()
   7 
   8 config(handler=handler, port=8080)
   9 mainloop()

这导致我在django等框架里入不了门...


反馈

创建 by -- ZoomQuiet [2010-11-09 01:59:45]

MiscItems/2010-11-09 (last edited 2010-11-09 02:01:30 by ZoomQuiet)