摘要: In [30]: dq Out[30]: deque([3, 4, 5, 6, 7, 8, 9, 11, 22, 33]) extendleft(iter),在队列的左边插入元素,逆序插入 In [31]: dq.extendleft([55,66,77,88]) In [32]: dq Out[3 阅读全文
posted @ 2019-04-02 15:50 superniao 阅读(272) 评论(0) 推荐(0) 编辑
摘要: contextlib模块中包含的工具用于处理上下文管理器和with语句 上下文管理器由with语句启用,执行流进入with中的代码块会运行__enter__()方法,它返回在这个上下文中使用的一个对象,执行流离开with块时,则执行上下文管理的__exit__(exc_type,exc_val,ex 阅读全文
posted @ 2019-03-31 21:58 superniao 阅读(115) 评论(0) 推荐(0) 编辑
摘要: for i in range(10): if i == 5: break print(i) else: print('*'*10) #程序触发break else语句不会执行 for i in range(10): if i == 5: continue print(i) else: print('*'*10) ... 阅读全文
posted @ 2019-03-31 21:38 superniao 阅读(101) 评论(0) 推荐(0) 编辑
摘要: python的第一类对象的简易用法: 字符串的方法: 字典的方法: 阅读全文
posted @ 2019-03-31 18:09 superniao 阅读(126) 评论(0) 推荐(0) 编辑
摘要: 闭包:在内层函数中访问外层函数的变量 迭代器: 1、具有__iter__()方法的为可迭代对象iterable str list tuple dict 都是可迭代对象 2、生成迭代器,迭代器里面有__next__()方法, s = 'abcdefg' it = s.__iter__() #获取迭代器 阅读全文
posted @ 2019-03-30 21:35 superniao 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 改进版 阅读全文
posted @ 2019-03-24 13:29 superniao 阅读(1210) 评论(0) 推荐(0) 编辑
摘要: import os import fnmatch """根据指定文件名格式,筛选符合条件的文件,把文件的路径加上文件名一起返回""" def is_file_match(filename, patterns): """ 判断符合指定模式的文件名 :param filename: 文件名 :param patterns: 文件名模式的列表 :return... 阅读全文
posted @ 2019-03-24 13:15 superniao 阅读(1409) 评论(0) 推荐(0) 编辑
摘要: import paramiko import psutil def bytes2human(n): """ 字节转化成相应容量值 :param n: 字节数 :return: """ # 容量单位 symbols = ('K','M','G','T') prefix = {} for i, s in enumerate... 阅读全文
posted @ 2019-03-23 21:44 superniao 阅读(182) 评论(0) 推荐(0) 编辑
摘要: 1、查看包的版本号 例如:查看paramiko的版本号 >>> import paramiko>>> paramiko.__version__'2.4.2'>>> 2、包的升级 升级pip python -m pip install --upgrade pip 3、检查需要升级的包 pip list 阅读全文
posted @ 2019-03-23 20:37 superniao 阅读(104) 评论(0) 推荐(0) 编辑
摘要: pip3 install ipython #找到安装的目录 find / -name ipython /usr/local/python37/bin/ipython #增加快速快捷 vim ~/.bashrc 增加 alias ipython3='python37 /usr/local/python 阅读全文
posted @ 2019-03-20 11:41 superniao 阅读(756) 评论(0) 推荐(0) 编辑