- 对象转换器,提供load_xxx/dump_xxx方法
- 对象验证器,定义一个模式,判断一个Python对象是否符合该模式. validate
- 对象生成器,generate
- 提供其他库的插件:
- flask/django等Web框架的表单验证插件
- pymongo 扩展
目标在于提供Pythonic的对象验证方式,如:
const Decimal = require('decimal.js'); | |
// 计算表达式的值 | |
function calculate(expression) { | |
const words = splitExpression(expression); | |
const outputs = []; | |
const signs = []; | |
while (words.length) { | |
const word = words.shift(); |
# -*- 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}, |
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'): |
import importlib | |
import pkgutil | |
for loader, name, is_pkg in pkgutil.walk_packages(__path__): | |
importlib.import_module('.{}'.format(name), 'models') |
# 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 |
-- 条件为IN的时候是51条,条件为Not In的时候应该是7条结果是0 | |
SELECT | |
DISTINCT CH || QH AREACODE | |
FROM PTB_YHZL | |
-- 58 rows | |
WHERE PTB_YHZL.CH || QH NOT IN ( | |
SELECT PTB_DQ.CH || QH | |
FROM PTB_FCXX | |
LEFT JOIN ptb_dq ON PTB_FCXX.CH = PTB_DQ.CH | |
-- 53 rows |
CREATE TABLE TABLE_A | |
( | |
AID NUMBER(10) NOT NULL PRIMARY KEY | |
); | |
CREATE TABLE TABLE_B | |
( | |
BID NUMBER(12) NOT NULL PRIMARY KEY, | |
AID NUMBER(10) NOT NULL REFERENCES TABLE_A (AID) | |
); |
import collections | |
class groupby2(object): | |
""" | |
[k for k, g in groupby2('AAAABBBCCDAABBB')] --> A B C D | |
""" | |
def __init__(self, iterable, key=lambda x: x): | |
self.key_func = key |
*** Error in `/home/jeffrey/workspace/romulan-env/bin/python2.7': free(): corrupted unsorted chunks: 0x00000000036437e0 *** | |
======= Backtrace: ========= | |
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fcf86e667e5] | |
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7fcf86e6f37a] | |
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fcf86e7353c] | |
/home/jeffrey/workspace/romulan-env/bin/python2.7[0x509019] | |
/home/jeffrey/workspace/romulan-env/bin/python2.7[0x4b5244] | |
/home/jeffrey/workspace/romulan-env/bin/python2.7[0x4a6359] | |
/home/jeffrey/workspace/romulan-env/local/lib/python2.7/site-packages/pymssql.so(+0x20cb2)[0x7fcf738a9cb2] | |
/home/jeffrey/workspace/romulan-env/bin/python2.7(PyEval_EvalFrameEx+0x5780)[0x4c9780] |