python 的琐碎事

1、imp 模块提供访问内部import语句的实现机制。

import imp
data = {"class":"re","func":"finditer"}
def call(data):
    file,path,desc = imp.find_module(data["class"])
    mymould = imp.load_module(data["class"],file,path,desc)
    myfunc = mymould.__dict__.get(data["func"])
    return myfunc

str = """<aaa>11111</aaa>"""
match = call(data)(r"<aaa>([\w\s]*)</aaa>",str)
for i in match:
    print i.groups(1)

2、re模块



3、list的sort

students = [{'a':12,'b':34},{'a':1,'b':23},{'a':1,'b':11}];


students.sort(cmp=lambda x,y:cmp(x.get('a'),y.get('a')))
print students;

#推荐
students.sort(key=lambda x:x.get('a'),reverse=True)
print students

#多建值排序
students.sort(key=lambda x:(x.get('a'),x.get('b')))
print students

sorted使用与list的sort类似


4、datetime

import time
from datetime import datetime

now_time_stamp = time.time()
utc = time.gmtime(now_time_stamp)
print now_time_stamp
active_date = datetime.fromtimestamp(now_time_stamp)
print datetime.strftime(active_date, '%Y%m%d--%H:%M')

date_stamp = time.mktime(utc)
date = datetime.fromtimestamp(date_stamp)
print datetime.strftime(date, '%Y%m%d--%H:%M')


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值