- 博客(7)
- 收藏
- 关注
转载 python_简易ORM
让我们来尝试编写一个ORM框架。编写底层模块的第一步,就是先把调用接口写出来。比如,使用者如果使用这个ORM框架,想定义一个User类来操作对应的数据库表User,我们期待他写出这样的代码:class User(Model): # 定义类的属性到列的映射: id = IntegerField('id') name = StringField('username'
2016-09-09 12:27:19
2615
转载 python_type函数生成类对象的方法
type()函数既可以返回一个对象的类型,又可以创建出新的类型,比如,我们可以通过type()函数创建出Hello类,而无需通过class Hello(object)...的定义:>>> def fn(self, name='world'): # 先定义函数... print('Hello, %s.' % name)...>>> Hello = type('Hello', (
2016-09-09 10:27:36
2334
转载 python_时间戳和时间之间的转换
1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" 将其转换为时间数组 import time timeArray = time.strptime(a, "%Y-%m-%d %H:%M:%S") 转换为时间戳: timeStamp = int(time.mktime(timeArra
2016-09-02 11:07:46
430
原创 python_使用sched实现定时功能
import sched,times = sched.scheduler(time.time,time.sleep)def print_time(): print(time.strftime('%y%m%d:%H:%M:%S'))print_time()s.enter(5,1,print_time)s.enter(10,1,print_time)s.run()
2016-09-01 12:53:40
1369
原创 python_使用asycnio协程的一些经验
import asyncio@asyncio.coroutinedef common_generator(id): for i in range(0, 5): yield from asyncio.sleep(1) print("the id is :", id)def test_coroutine(id): yield from co
2016-09-01 12:33:48
474
原创 python_使用email模块发送简单邮件
from email.header import Headerfrom email.mime.text import MIMETextimport smtplibdef mail_message(from_address, to_address, password, header, msg, smtp_server='smtp.126.com', port='25'): """
2016-09-01 12:28:43
1113
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人