您的位置:首页 > 编程语言 > Python开发

【Python模块】os & linecache & hashlib & commands & sys & time & datetime

2016-09-05 16:07 1046 查看
python模块整理

一、os模块

【1】os.walk(dir_path) 遍历某路径下的所有文件



【2】os.path.join(path, name) 连接目录与文件名或目录

【3】os.path.exists(name)判断是否存在文件或目录name



【4】os.path.getsize(name) 获得文件大小



【5】参考链接

http://developer.51cto.com/art/201003/186045.htm

二、linecache模块

【1】linecache.getline(filename, lineno)获取文件的某一行的内容



【2】linecache.getlines(filename) 获取文件的全部内容,输出为列表格式



【3】参考链接

http://www.csdn123.com/html/topnews201408/98/9498.htm

三、hashlib模块

【1】MD5:hashlib.md5(data).hexdigest()



【2】SHA-1:hashlib.sha1(data).hexdigest()



【3】参考链接

http://www.cnblogs.com/the4king/archive/2012/02/06/2340660.html

四、commands模块

【1】commands.getoutput(command) 用于调用Linux shell命令,并返回状态和结果



【2】参考链接

http://blog.csdn.net/dbanote/article/details/9414133

五、subprocess模块

【1】subprocess.Popen(command, shell=True)用于调用Linux shell命令,并返回returncode属性和执行结果



【2】return_code如果为127,表示command not found,也就是上例apktool命令not found

【3】参考链接

http://blog.csdn.net/g457499940/article/details/17068277

六、sys模块

【1】sys.path动态改变Python的搜索路径,加入到PATH环境变量中



【2】参考链接

http://blog.csdn.net/l_b_yuan/article/details/52260646

七、time模块

【1】time.time()获取当前时间(时间戳的形式)



【2】参考链接

http://www.jianshu.com/p/da0ef08c9ea7

八、datetime模块

【1】datetime.datetime.now()获取当前时间



【2】参考链接

http://peiqiang.net/2014/08/15/python-time-and-datetime.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息