- 对象转换器,提供load_xxx/dump_xxx方法
- 对象验证器,定义一个模式,判断一个Python对象是否符合该模式. validate
- 对象生成器,generate
- 提供其他库的插件:
- flask/django等Web框架的表单验证插件
- pymongo 扩展
目标在于提供Pythonic的对象验证方式,如:
# encoding=utf8 | |
from decimal import Decimal | |
def create_ladders(price_name, last_reading, current_reading, price): | |
""" 目前不考虑优惠,但是可以合计金额里面体现出来 | |
ladder['price_name'] = price_name | |
ladder['last_reading'] = last_reading | |
ladder['current_reading'] = current_reading | |
ladder['gas'] = current_reading - last_reading |
import importlib | |
import pkgutil | |
for loader, name, is_pkg in pkgutil.walk_packages(__path__): | |
importlib.import_module('.{}'.format(name), 'models') |
import datetime | |
import arrow | |
def diff_month(d1, d2): | |
return (d1.year - d2.year) * 12 + d1.month - d2.month | |
def calc_current_period(start_date, period, now=None, unit='months'): |
# -*- coding: utf-8 -*- | |
import datetime | |
from collections import defaultdict | |
FLIGHTS = { | |
"chengdu_to_xian": { | |
"reward": [ | |
{'name': 'GD2501', 'time': '08:00', 'price': 500, 'at_weekends': True}, | |
{'name': 'GD2501', 'time': '08:00', 'price': 800, 'at_weekends': False}, | |
{'name': 'GD2606', 'time': '12:25', 'price': 500, 'at_weekends': True}, |
const Decimal = require('decimal.js'); | |
// 计算表达式的值 | |
function calculate(expression) { | |
const words = splitExpression(expression); | |
const outputs = []; | |
const signs = []; | |
while (words.length) { | |
const word = words.shift(); |