随笔分类 -  C.python

摘要:# 导入画图函数 import matplotlib.pyplot as plt # 创建画布, figsize:指定图的长宽, dpi:图像的清晰度,返回fig对象 plt.figure(figsize=(20, 8), dpi=100) # 创建X,Y坐标轴数据 x = [1,2,3,4,5] 阅读全文
posted @ 2022-12-21 16:14 ForLivetoLearn 阅读(50) 评论(0) 推荐(0) 编辑
摘要:原文:https://blog.csdn.net/caicaibird0531/article/details/90694849 一、etree的Element类 1.通过etree.Element()创建XML树 from lxml import etree root = etree.Elemen 阅读全文
posted @ 2022-06-14 10:27 ForLivetoLearn 阅读(5769) 评论(0) 推荐(0) 编辑
摘要:glob库用于文件查找,支持通配符(*、?、 []) #示例1:查找目录中所有以.sh为后缀的文件: >>> glob.glob('/home/user/*.sh') ['/home/user/b.sh', '/home/user/a.sh', '/home/user/sum.sh'] #示例2:查 阅读全文
posted @ 2020-11-10 16:28 ForLivetoLearn 阅读(125) 评论(0) 推荐(0) 编辑
摘要:subprocess库用于执行Shell命令, 工作时会fork一个子进程去执行任务,连接到子进程的标准输入、输出、错误,并获得它们的返回代码。这个模块将取代os.system、 os.spawn*、 os.popen*、 popen2.*和commands.*。 subprocess的主要方法: 阅读全文
posted @ 2020-11-10 16:25 ForLivetoLearn 阅读(132) 评论(0) 推荐(0) 编辑
摘要:异常 try: 尝试代码 except 错误类型1: 处理代码 except 错误类型2: 处理代码 except (错误类型3,错误类型4) 处理代码 except Exception as result: #这里的Exception可以匹配所有异常 print(result+'这里是把异常当作结 阅读全文
posted @ 2020-11-10 15:15 ForLivetoLearn 阅读(88) 评论(0) 推荐(0) 编辑
摘要:定义类 class 类名: def 函数名(self): #哪个对象调用这个方法,self就是哪个对象 语句 def 函数名(self): #类中定义函数,第一个参数要是self 语句 变量=类名() #创建类 类的内置方法 class cat(): def __new__(self): #在ini 阅读全文
posted @ 2020-04-01 11:05 ForLivetoLearn 阅读(158) 评论(0) 推荐(0) 编辑
摘要:注释 ###单行注释 ''' 多行注释 ''' #TODO注释,这种注释会高亮显示 比较 ''' is 比较的是地址 == 比较的是值 ''' a = [1,2,3] b = [1,2,3] c = a print(a is b) print(a == b) print(a is c) False 阅读全文
posted @ 2020-03-31 21:15 ForLivetoLearn 阅读(161) 评论(0) 推荐(0) 编辑
摘要:1.通过命令行1秒启动一个下载服务器 2.通过命令行将字符串转JSON 3.通过命令行判断第三方库是否安装 阅读全文
posted @ 2019-10-21 22:13 ForLivetoLearn 阅读(173) 评论(0) 推荐(0) 编辑
摘要:pip常用命令 install:安装软件 download:下载软件 uninstall:卸载软件 freeze:输出本地软件环境到文件中pip freeze > requirements.txt,可以在其他服务器通过pip install -r requirements.txt直接安装软件 lis 阅读全文
posted @ 2019-10-21 22:06 ForLivetoLearn 阅读(116) 评论(0) 推荐(0) 编辑
摘要:安装python3环境 #1.安装依赖条件 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel t 阅读全文
posted @ 2019-10-14 16:26 ForLivetoLearn 阅读(386) 评论(0) 推荐(0) 编辑
摘要:进程:资源分配的基本单位,进程数量为cpu核数+1,os.cpu_count()。计算密集时,使用进程 守护进程随着主进程的最后一句代码结束而结束 使用process模块可以创建进程 方法 多进程启动 属性 示例 锁机制 信号机制 事件机制 队列 进程间共享内存 进程池 阅读全文
posted @ 2019-09-26 15:49 ForLivetoLearn 阅读(614) 评论(0) 推荐(0) 编辑
摘要:1.socket参数 2.TCPsocket常用方法 TCP socket client server 实例化 sk = socket.socket() sk = socket.socket() 绑定地址开启监听 / sk.bind(('127.0.0.1',8888))sk.listen() 连接 阅读全文
posted @ 2019-09-18 15:06 ForLivetoLearn 阅读(206) 评论(0) 推荐(0) 编辑
摘要:1.导入模块 >>> import logging 2.五种日志级别 #输出时默认只显示警告级别以上的信息,可以使用basicConfig的level参数更改 >>> logging.basicConfig(level=logging.DEBUG) ... logging.debug('调试') . 阅读全文
posted @ 2019-09-17 13:53 ForLivetoLearn 阅读(181) 评论(0) 推荐(0) 编辑
摘要:比urllib.request更方便的爬虫工具 官方中文文档:http://cn.python-requests.org/zh_CN/latest/ 安装 pip install requests # 或者用pycharm点点点 导入模块 >>> import requests 网页的基本用法,GE 阅读全文
posted @ 2019-09-06 10:38 ForLivetoLearn 阅读(188) 评论(0) 推荐(0) 编辑
摘要:官方文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc.zh/ 使用前需要先安装模块,并安装解析器 pip install beautifulsoup4 pip install lxml pip install html5lib 安装完成 阅读全文
posted @ 2019-08-13 17:05 ForLivetoLearn 阅读(191) 评论(0) 推荐(0) 编辑
摘要:python使用正则表达式之前需要先倒入re模块 import re 可选标志位 re.A ASCII,使得 \w,\W,\b,\B,\s 和 \S 只匹配 ASCII 字符,而不匹配完整的 Unicode 字符。这个标志仅对 Unicode 模式有意义,并忽略字节模式。 re.I IGNORECA 阅读全文
posted @ 2019-08-12 16:58 ForLivetoLearn 阅读(1294) 评论(0) 推荐(0) 编辑
摘要:python使用代理的方法有两种 1. 2. 示例代码: 阅读全文
posted @ 2019-08-06 14:35 ForLivetoLearn 阅读(10483) 评论(0) 推荐(0) 编辑
摘要:添加头部信息有两种方法 1.通过添加urllib.request.Request中的headers参数 2.通过urllib.request.Request的add_header方法添加 360翻译示例代码: 阅读全文
posted @ 2019-08-06 11:35 ForLivetoLearn 阅读(8770) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示