标签归档:Python

python import this python 哲学

Published / by 高成 / Leave a Comment


Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>

Beautiful is better than ugly.
优美胜于丑陋。
Explicit is better than implicit.
明了胜于晦涩。
Simple is better than complex.
简单胜过复杂。
Complex is better than complicated.
复杂胜过凌乱。
Flat is better than nested.
扁平胜于嵌套。
Sparse is better than dense.
间隔胜于紧凑。
Readability counts.
可读性很重要。
Special cases aren't special enough to break the rules.
即便假借特例的实用性之名,也不可违背这些规则。
Although practicality beats purity.
虽然实用性次纯度。
Errors should never pass silently.
错误不应被无声的忽略。
Unless explicitly silenced.
除非明确地沉默。
In the face of ambiguity, refuse the temptation to guess.
当存在多种可能,不要尝试去猜测。
There should be one-- and preferably only one --obvious way to do it.
应该有一个 - 最好只有一个 - 明显的能做到这一点。
Although that way may not be obvious at first unless you're Dutch.
虽然这种方式可能不容易,除非你是 Python 之父。
Now is better than never.
现在做比不做好。
Although never is often better than *right* now.
虽然过去从未比现在好。
If the implementation is hard to explain, it's a bad idea.
如果这个实现不容易解释,那么它是个坏主意。
If the implementation is easy to explain, it may be a good idea.
如果这个实现容易解释,那么它或许是个好主意。
Namespaces are one honking great idea -- let's do more of those!
命名空间是一种绝妙的理念,我们应当多加利用。

简述uWSGI+Nginx+Python 搭建过程

Published / by 高成 / 简述uWSGI+Nginx+Python 搭建过程有1条评论

由于服务器上面的Python和Nginx都已经安装完毕,咱们就直接叙述uWSGI的安装,对照各方面的测试数据uWsgi在性能方面相对其他方式还是比较不错的!他是一个快速的、纯C语言开发的、自维护的、对开发者或是系统管理员友好的应用程序服务器。

官方网址:http://projects.unbit.it/uwsgi/

文档地址:http://projects.unbit.it/uwsgi/wiki/Doc

准备

cd /usr/local
wget http://projects.unbit.it/downloads/uwsgi-1.0.2.1.tar.gz

安装

tar zxvf uwsgi-1.0.2.1.tar.gz
cd uwsgi-1.0.2.1/
python uwsgiconfig.py --build

配置

cp nginx/uwsgi_params /usr/local/nginx/conf/
vi /usr/local/nginx/conf/nginx.conf

编辑Nginx配置文件添加,uWSGI监听8000端口,这个原理跟PHP的fastcgi相同

    server {
        listen        80;
        server_name py.wuwangwo.net;

        location / {
            root  /data/htdocs/py.wuwangwo.net;
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:8000;
        }

        access_log  /data1/logs/py.wuwangwo.net.access.log;
    }

重新启动Nginx

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf -s reload

配置web站点

cd /data/htdocs/py.wuwangwo.net
vi uwsgi.xml

编辑uWSGI配置文件,他也同样支持.ini文件等的配置形式,个人习惯不同,具体可以参照官方示例:http://projects.unbit.it/uwsgi/wiki/Example


127.0.0.1:8000
myuwsgi

/data/htdocs/py.wuwangwo.net
2

编辑web.py文件

#!/usr/bin/env python

import os
import web

urls = ('/(.*)', 'hello')

app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = "World"
        return "Hello" + name + "!"

application = app.wsgifunc()

启动uWSGI,添加--daemonize参数以后台方式运行

/usr/local/uwsgi-1.0.2.1/uwsgi -x /data/htdocs/py.bukaopu.org/uwsgi.xml --daemonize /data/htdocs/py.wuwangwo.net/uwsgi.error.log

停止uWSGI

killall -9 uwsgi