装饰符函数的传入变量为:使用装饰符的函数(目标函数)。其本质是:在调用目标函数之前,插入调用装饰符函数,然后由装饰 …
代码
import datetime, calendar, time
def timestamp2datetime(timestamp):
    return datetime.datetime.fromtimestamp(timestamp)
def date2timestamp(date):
    """local time"""
    return calendar.timegm(date.timetuple())
def date2timestamp_utc(date):
    """utc time"""
    return int(time.mktime(date.timetuple()))
def datetime2timestamp(year, month, day):
    return calendar.timegm(datetime.datetime(year, month, day).timetuple())
def …查找比对的时候是数值类型,性能还是很不错的
from collections import namedtuple
def MakeEnum(enumList):
    return namedtuple('Enum', enumList)._make(range(len(enumList)))
USER_AT = MakeEnum(['noLogined', 'logined', 'hall', 'room'])
print USER_AT, type(USER_AT)
print USER_AT.noLogined, type(USER_AT …#!/usr/bin/env python
#coding=utf-8
#----------------------------------------------------------------------
def obj2map(obj):
    """"""
    return vars(obj)
########################################################################
class obj:
    def __init__(self):
        self.a = 1
        self.b = 2
########################################################################
class map2struct:
    def __init__(self, **entries):
        self.__dict__.update(entries)
o = obj()
print '~~~~~~~~~~~~~~ obj -> map ~~~~~~~~~~~~~~'
m = vars(o)
print type(m), m
print '~~~~~~~~~~~~~~ map -> obj ~~~~~~~~~~~~~~'
o2 = map2struct …获得符号表的方法
nm libfoo.so
演示工程目录结构
~/projectRoot
    bin
        libfoo.so
    script
        build.sh
    src
        libfoogo
            libforgo.go
        libfoogo_test
            main.go
构建脚本 build.sh
#!/bin/bash
cd ../bin
export GOPATH=~/projectRoot
go build libfoogo_test
cd …很多时候用 Python 写的小工具需要打包成一个可执行文件交给使用者,比如:
- 使用者没有安装 Python 或者第三方库环境
- 为了便于 …
SQLite对事务机制的支持是不完整的,Django 1.6 开始对事物的支持迁移到了有数据库直接支持。
手上正好有个项目是很久以前的,部分开发调整环境还行想继 …
#!/usr/bin/env python
#coding=utf-8
uuu = u'中文'
print type(uuu), uuu
sss = uuu.encode('gbk')
print type(sss), sss
nnn = unicode(sss, 'gbk')
print type(nnn), nnn
输出为
<type 'unicode'> 中文
<type 'str'> 中文
<type 'unicode'> 中文
整体思路是
- 使用 TEMPLATE_CONTEXT_PROCESSORS 在模板中激活全局上下文
- 使用 bootstrap 库实现 CSS 效果
- 在模板文件中调用全局变量完成实现
在 settings.py 中添加 …
创建分支
Hg 的分支相对于 Git 没那么随意,如果要实现偏 Git 风格分支可以使用 bookmark 也就是书签功能 创建需要两步:
- 设置新的 …
