python小知识点学习笔记

time模块的一些用法:

#coding:utf-8
import time

a = time.time()                 #返回时间戳
print a
b = time.ctime(a)              #返回时间字符串
print b
c = time.strptime(b)          #时间字符串转为时间对象
print c
d = time.strftime('%Y-%m-%d %H:%M:%S',c)   #格式化输入时间
print d

'''
结果:
1384218247.53
Tue Nov 12 09:04:07 2013
time.struct_time(tm_year=2013, tm_mon=11, tm_mday=12, tm_hour=9, tm_min=4, tm_sec=7, tm_wday=1, tm_yday=316, tm_isdst=-1)
2013-11-12 09:04:07
'''
View Code

 glob-文件名模式匹配

#coding:utf-8
import glob

for name in glob.glob('d:/*/[a-e][1-5]*.txt'):
    print name
'''
[a-e][1-5]用来匹配区间,也可[as23]匹配任意一个,通配符包括*和?
'''
View Code

 shutil-高级文件处理

#coding:utf-8
import shutil

shutil.copyfile('d:/ab.txt','d:/ab/cd.txt')  #复制文件
shutil.copytree('d:/ab','d:.cd')                #复制目录
shutil.move('d:/ab','d:/cd')                    #移动
View Code

 itertools-迭代器例子

#coding:utf-8
import itertools

for i in itertools.imap(lambda x:x*2,range(10)):
    print i

for i in map(lambda x:x*2,range(10)):
    print i

'''这个例子map返回列表,imap返回迭代器'''
View Code
原文地址:https://www.cnblogs.com/bbcar/p/3418924.html