Python:Hello World级别的SimpleDb
2014-05-03 11:15
330 查看
背景
几乎所有的动态语言都支持成员的动态解析,一般的在解析不到成员的时候会给出一个hook点让你自定义一些有意思的实现。.Net4之后增加了对动态类型的支持,在动态类型上就有这种机制。模拟SimpleDb
# coding = utf-8 class SimpleDB: def __getattribute__(self, name): return Table(name) class Table: def __init__(self, table): self.__table = table def select(self, condition): print('table: %s, condition: %s' % (self.__table, condition)) test = SimpleDB() test.Users.select({'name': '段光伟', 'age': 30})
注意:上面的__getattribute__就是python提供的hook。
相关文章推荐
- Python 之 Selenium(1)Hello World
- Python 自学笔记(二)第一个程序 Hello World
- Python教程一:Hello World!
- Python3.5 安装 & hello world
- Python脚本调用C#代码数据交互示例(hello world)
- Python基础01——Hello World!
- python,hello world
- python 的第一个小程序 Hello world!
- python基础教程学习笔记 — ‘Hello World’
- python--hello world
- hello world 级别模块程序
- python(1) - 第一个程序 Hello World!
- 建立一个Hello World级别的Spring项目
- python日志级别
- 在.NET外散步之我爱贪吃蛇Python -hello world
- python-django学习笔记-第一个hello world
- 【Python】Hello World 输入输出
- python PyQt5初级教程hello world
- 用 eric6 与 PyQt5 实现python的极速GUI编程(系列01)--Hello world!
- python学习之--Hello World