Skip to content

Instantly share code, notes, and snippets.

@nature-python
nature-python / python常量.md
Last active August 29, 2015 13:57
python中如何实现静态语言的const

Python 中常量的实现

实现方法来源于**《Python Cookbook》**,发放就是把值放在这个对象的__dict__字典中,当增加或者改变值的时候就在__dict__中寻找是否,有则报错,否则则存入

class _const(object):
	class ConstError(TypeError):
		pass
	def __setattr__(self,name,value):
 if self.__dict__.has_key(name):
@nature-python
nature-python / 微博荟萃.md
Last active August 29, 2015 13:57
链接有意思的blog,顺带帮作者提高下PageRank
@nature-python
nature-python / python生成器
Created March 12, 2014 04:26
yield用途用法
待完成
@nature-python
nature-python / python装饰符.md
Last active August 29, 2015 13:57
python装饰符@学习,装饰函数

#python decorator @

python装饰器是对原函数的一层包装,旨在为原函数或者类似函数增加一个共同或者额外的功能

  1. 使用范式:先定义修饰函数,然后再用@来装饰原函数
#修饰函数方式一:
def dec(f):
  #do something here
@nature-python
nature-python / python类详解.md
Last active August 29, 2015 13:57
python类的创建继承,classmethod和staticmethod的区别,类变量和实例变量的区别,@Property,新式类(new style class)和经典类( classic class)

#Python类学习

python是面向对象(OOP)的,类是实现面向对象的方式,与其他语言的类略有不同,python的类比较简单。

  • 创建类
class SchoolMember(object):
  def __init__(self,name,age):
    self.name=name
@nature-python
nature-python / wsgi和tornado.md
Last active May 14, 2017 11:38
python wsgi 与 tornado

#WSGI:(web server gateway interface)WEB服务器网关接口 WSGI是为python语言定义的web服务器和web应用程序或框架之间的一种简单而实用的借口。wsgi是一个web组件的接口规范,它将web组件分为三类:server,middleware,application

##wsgi server wsgi server可以理解为一个符合wsgi规范的web server,接收request请求,封装一系列环境变量,按照wsgi规范调用注册的wsgi app,最后将response返回给客户端。文字很难解释清楚wsgi server到底是什么东西,以及做些什么事情,最直观的方式还是看wsgi server的实现代码。以python自带的wsgiref为例,wsgiref是按照wsgi规范实现的一个简单wsgi server。其工作流程如下:

  1. 服务器创建socket,监听端口,等待客户端连接。
  2. 当有请求来时,服务器解析客户端信息放到环境变量environ中,并调用绑定的handler来处理请求。
  3. handler解析这个http请求,将请求信息例如method,path等放到environ中。
  4. wsgi handler再将一些服务器端信息也放到environ中,最后服务器信息,客户端信息,本次请求信息全部都保存到了环境变量environ中。
@nature-python
nature-python / 使用python进行图处理
Created December 3, 2013 03:22
ubuntu desktop 13.10 安装matplotlib,networkx,graphviz,pygrapyviz
待完成
@nature-python
nature-python / tornado-server.md
Created August 26, 2013 10:06 — forked from chen206/tornado-server.md
如何安装web-server

AptGet source.list

/etc/apt/source.list

deb http://cn.archive.ubuntu.com/ubuntu/ precise main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ precise main restricted

deb http://cn.archive.ubuntu.com/ubuntu/ precise-updates main restricted
deb-src http://cn.archive.ubuntu.com/ubuntu/ precise-updates main restricted