python模块

os(.stat;.path)

os.path.split:拆分路径,返回tuple,第一个元素是路径,第二个元素是文件名。

os.path.basename:获取文件名(因为多平台适用,因此不一定有后缀)。

os.path.dirname:获取路径对应的路径。

os.path.splitext:讲路径、文件名、扩展名分开,并以一个tuple的形式返回。

os.path.commonprefix:在一组路径中,找到一个共同的前缀。

os.path.join:将零散的字符串拼合成一个安全的路径表示。

os.path.expanduser:寻找用户的home目录。

os.path.expandvars:

os.path.normpath:处理不规则路径字符串,将其转化为正常的路径。

os.path.abspath:将相对路径转换为绝对路径。

fnmatch

fnmatch(name,pattern):测试name是否匹配pattern,匹配返回true,否则返回false。

filter(names,pat):实现列表特殊字符的过滤或筛选,返回符合匹配模式的字符列表。

fnmatchcase(name,pat):强制区分大小写匹配。

translate(pat):将pat转换成正则表达式。

time

time.time():获取当前时间戳。

time.ctime():获取格式化后的时间。

time.clock():返回cpu时钟。

random

random.randint():生成随机整数。

random.randrange():随机选取制定整数序列中的某个元素。

random.random()和random.uninform():生成随机浮点数。

random.choice()和random.sample():生成随机字符,字符串。

random.shuffle():打乱排序。

原文地址:https://www.cnblogs.com/lswit/p/4644101.html