Python
乱写乱画
一个用来记录笔记的博客
展开
-
langid 代码对应的语种名
langid 代码对应的语种名原创 2023-02-20 16:01:30 · 449 阅读 · 0 评论 -
pymysql sql语句中引号问题
【代码】pymysql sql语句中引号问题。原创 2022-09-28 11:42:33 · 236 阅读 · 0 评论 -
/backend_agg.py:238: RuntimeWarning: Glyph 26085 missing from current font.
linux 使用python matplotlib画图时没有字体显示中文,导致中文乱码 删除matplotlib字体缓存 rm -rf /home/ubuntu/.cache/matplotlib 然后在python中指定字体,即可正常显示中文原创 2022-06-09 15:05:07 · 753 阅读 · 1 评论 -
Python3通过writerow写入csv文件 多了一条空行
1.声明csv.writer() 时 将dialect设置为unix,换行符即为'\n'with open(self.game_name + '2022.csv', 'w', encoding='utf-8-sig') as f: writer = csv.writer(f, dialect='unix') # 将dialect设置为unix,换行符即为'\n' writer.writerow(self.bilibili_columns)原创 2022-05-31 15:59:49 · 1045 阅读 · 0 评论 -
pymysql 重连
self.conn.ping(reconnect=True)原创 2021-11-01 10:23:29 · 606 阅读 · 0 评论 -
windows下python使用protobuf的开门级教程
转载自:https://blog.csdn.net/u013992365/article/details/81287041一、在windows下编译python所需的protobuf的相关文件1、首先下载protobuf源码(后一个是我自己从github上down的,因为版本是3.6.0,因为网不好下了很久,但是这个是完全体,就是我把包括python在内的全部版本都下了下来):https://github.com/google/protobuf/releases/tag/v3.6.0或是:http转载 2021-07-23 16:07:43 · 875 阅读 · 2 评论 -
is not clickable at point (530, 16). Other element would receive the click
使用selenium发送点击请求报错翻译了一下不能点击,被其他元素接受了请求解决方法1button.send_keys("\n") #方法2from selenium.webdriver.common.keys import Keysbutton.send_keys(Keys.SPACE) #方法3driver.execute_script("arguments[0].click();", button)经过gen...原创 2021-06-15 17:07:33 · 168 阅读 · 0 评论 -
ValueError: check_hostname requires server_hostname
python3 爬取数据时报错requests.get("https://www.baidu.com/", proxies={'http': 'http://183.53.29.159:25862', 'https': 'https://183.53.29.159:25862'})原创 2021-06-10 15:46:28 · 134 阅读 · 0 评论 -
TypeError: __init__() takes 1 positional argument but 5 positional arguments (and 1 keyword-only arg
python脚本迁移时报错:TypeError: __init__() takes 1 positional argument but 5 positional arguments (and 1 keyword-only argument) were given原因:原创 2021-06-08 15:34:48 · 1019 阅读 · 1 评论 -
python 保留小数位数
a = 12.345a1 = round(a, 2)print(a1)原创 2021-04-22 11:05:20 · 144 阅读 · 0 评论 -
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
http://npm.taobao.org/mirrors/chromedriver/89.0.4389.23/1,到这个地址下载浏览器对应的浏览器驱动2,将安装包解压代码指定驱动路径webdriver.Chrome(r'E:\ChromeDriver\chromedriver.exe', chrome_options=chrome_options)原创 2021-04-19 10:12:09 · 345 阅读 · 0 评论 -
selenium 自动下载对应Chrome版本
from webdriver_manager.chrome import ChromeDriverManagerbrowser = webdriver.Chrome(ChromeDriverManager().install())原创 2021-04-16 16:24:34 · 236 阅读 · 0 评论 -
python sorted 处理二维数组排序
>>> l = [[1, 2, 3], [2, 3, 4], [2, 1, 3]]>>> sorted(l, key=lambda l: l[1], reverse=True)[[2, 3, 4], [1, 2, 3], [2, 1, 3]]>>> sorted(l, key=lambda l: l[1])[[2, 1, 3], [1, 2, 3], [2, 3, 4]]原创 2021-03-17 14:42:15 · 2987 阅读 · 0 评论 -
pip install 安装第三方库报错SSL: CERTIFICATE_VERIFY_FAILED
bootstrap下载地址:https://v3.bootcss.com/getting-started/#download创建Django项目:django-admin startproject 项目名新建一个文件夹存储所有的APP mkdir APPS转载 2020-12-30 18:16:56 · 339 阅读 · 0 评论 -
python jsonpath与get 尝试获取json字符串中指定key
jsonpath:语法类似xpath,尝试指定范围获取所有符合条件的key,返回类型:listvalue 为json objimport jsonimport jsonpathjsonpath.jsonpath(value, "$..numComments")get 字典方法,尝试获取key,没有返回指定内容,默认为空>>> text = {"c":1, "a":1}>>> richtext2 = text.get('t', "")>&g.原创 2020-09-10 16:25:19 · 2157 阅读 · 1 评论 -
pandas数据处理--将txt中的数据进行去重统计数量
import pandas as pdimport numpy as npfrom openpyxl import load_workbookimport osimport reclass doWork: def __init__(self): self.txt_file_dir = "txt_file" self.excel_name1 = r"template.xlsx" # 模板文件 self.excel_name2 = r"sta.原创 2020-08-10 19:07:44 · 1170 阅读 · 0 评论 -
pandas 写入不同sheel
writer=pd.ExcelWriter('tarkov_market.xlsx') self.last_1_Y.to_excel(writer,sheet_name='last_1_M',index=0)#index=0:无索引 self.last_6_M.to_excel(writer,sheet_name='last_7_day',index=0) self.last_1_M.to_excel(writer,sheet_name='last_1_Y'.原创 2020-08-10 11:04:54 · 165 阅读 · 0 评论 -
Python 递归当前文件夹下的所有文件
def get_dir(code_file_dir): #获取目录路径 for root,dirs,files in os.walk(code_file_dir, followlinks=False): #遍历path,进入每个目录都调用visit函数,,有3个参数,root表示目录路径,dirs表示当前目录的目录名,files代表当前目录的文件名 print(root,dirs,files) for filename in files: f.原创 2020-08-10 10:25:48 · 271 阅读 · 0 评论 -
Python 报错重试 装饰器
def retry_on_failure(func): def wrapper(*args, **kwargs): flage = 0 while True: if flage >= 2: raise Exception('超过重试次数boom') try: return func(*args, **kwargs) excep.原创 2020-07-30 19:54:42 · 315 阅读 · 0 评论 -
Python 爬虫处理base64加密,解密方法
import base64import timectime = str(time.time())user_str = str({'user':user, 'user_type':user_type, 'user_id':user_id})# 加密token = base64.b64encode(user_str.encode(encoding='utf-8')).decode()# 解密user_str = base64.b64decode(token.encode(encoding='u.原创 2020-07-28 09:47:58 · 1213 阅读 · 1 评论 -
pandas 将两数据表进行拼接
将两文本内容以下图为例合并,空值补0:import pandas as pddef go(path1, path2, new_file_name): df1 = pd.read_csv(path1, encoding="utf-8") df2 = pd.read_csv(path2, encoding="utf-8") columns = df1.columns df_obj = pd.concat([df1,df2], sort=False) ..原创 2020-07-24 15:55:33 · 513 阅读 · 0 评论 -
Python 队列生产者,消费者模型
In [1]: from queue import Queue ...: ...: import random ...: ...: import threading ...: ...: import timeIn [3]: class Producer(threading.Thread): ...: def __init__(self, t_name, queue): ...: threading.Thread.__init__(.原创 2020-07-17 10:41:23 · 142 阅读 · 0 评论 -
Python No module named ‘sklearn.cross_validation‘
sklearn中已经废弃cross_validation,将其中的内容整合到model_selection中 将sklearn.cross_validation 替换为 sklearn.model_selection原创 2020-07-14 16:53:04 · 129 阅读 · 0 评论 -
python字典自定义排序,使用匿名函数根据字典value大小排序
d= {'a':24,'g':52,'i':12,'k':33}sorted(d.items(), key=lambda x : x[1], reverse=True)# d.items() 字典items将字典变为(key,value)的元组对象# key 自定义排序规则# reverse 是否倒序原创 2020-07-07 16:07:29 · 589 阅读 · 0 评论 -
python 数据写入json文件时中文显示Unicode编码问题
使用:json加载时数据出现Unicodereturn json.dumps(content)输出:{"Harris HBR Bipod": {"description": "Harris HBR ultralight foldable bipod with spring retraction mechanism. Used across the world by service operators and civilian shooters worldwide.\n", "General原创 2020-06-29 16:09:21 · 3764 阅读 · 0 评论 -
python 数据处理时去除emoji表情
方法一:emoji处理库,emoji官网:https://pypi.org/project/emoji/#安装 pip install emoji官方例子如下:清除命令:emoji.demojize(str)方法二:def filter_emoji(desstr,restr=''): #过滤表情 try: co = re.compile(u'[\U00010000-\U0010ffff]') except ..原创 2020-05-27 11:27:28 · 1986 阅读 · 0 评论 -
pymysql 将图片存入MySQL
帮忙写了个MySQL存储图片的脚本,在这留个记录MySQL建表语句:CREATE TABLE `image` ( `image_name` varchar(255) NOT NULL COMMENT '图片名', `game_name` varchar(255) NOT NULL COMMENT '图片所属游戏', `id` int NOT NULL AUTO_INCREMENT COMMENT '自增主键', `image` mediumblob COMMENT '图片内容',.原创 2020-05-21 16:38:36 · 1249 阅读 · 0 评论 -
python将中文字符转为浏览器传输格式%20,%3A
import urllib.parse as parseres = parse.quote("lang:ja until:2020-05-07 since:2020-05-06 ナルト", encoding="UTF-8")res'lang%3Aja%20until%3A2020-05-07%20since%3A2020-05-06%20%E3%83%8A%E3%83%AB%E3%83%88'res = parse.unquote('lang%3Aja%20until%3A2020-05-07%2.原创 2020-05-20 15:22:00 · 1172 阅读 · 0 评论 -
BeautifulSoup正则匹配
div_list = soup_obj.find_all("div", {"data-testid": re.compile(r"position: absolute;.*?;")})原创 2020-05-20 10:57:50 · 659 阅读 · 0 评论 -
pymysql创建游标,返回数据为字典类型
cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # 获取字典类型数据原创 2020-05-06 16:09:58 · 1166 阅读 · 0 评论 -
python 多线程读写MySQL
import pymysqlimport threadingimport datetimeimport randomimport requestsimport jsonimport reimport timeclass DB(object): """创建MySQL实例""" def __init__(self, host=None, username=None,...原创 2020-04-30 15:56:31 · 1070 阅读 · 0 评论 -
Python jieba分词使用方法记录
方法说明:jieba.cut 方法接受三个输入参数: 需要分词的字符串;cut_all 参数用来控制是否采用全模式;HMM 参数用来控制是否使用 HMM 模型 jieba.cut_for_search 方法接受两个参数:需要分词的字符串;是否使用 HMM 模型。该方法适合用于搜索引擎构建倒排索引的分词,粒度比较细,待分词的字符串可以是 unicode 或 UTF-8 字符串、GBK 字符串。...原创 2020-04-27 18:42:45 · 352 阅读 · 0 评论 -
Python 日期加减一天
import datetimestr(datetime.date.today() + datetime.timedelta(days=-1))原创 2020-04-24 14:51:36 · 666 阅读 · 0 评论 -
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
使用Django连接MySQL报错: raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or ne...原创 2020-01-21 14:26:23 · 189 阅读 · 0 评论 -
将数字时间转为日期
import datetimedatetime.datetime.fromtimestamp(1578141805)datetime.datetime(2020, 1, 4, 20, 43, 25)datetime.datetime.fromtimestamp(1577992610).strftime("%Y-%m-%d %H:%M:%S")'2020-01-03 03:16:50'...原创 2020-01-07 10:56:41 · 857 阅读 · 0 评论 -
python复习之字典dict
字典定义: 1.字典是一种可变的容器,可以存储任意类的数据 2.字典中每个数据都是用“键(key)”进行索引的(不像序列可以下标索引) 3.字典中 的数据没有先后关系,字典的存储是无序的 4.字典中的数据是以键(key)-值(value)对的形式进行存储 5.字典的键不能重复,且只能用不可变类型做为字典的键字典的字面值表示方法: 以{...原创 2019-05-23 11:23:27 · 254 阅读 · 0 评论 -
python 复习之元组tuple
什么是元组: 元组是不可变的序列,和list一样可以存放任意类型的元素。字面值的表示方法: 用小括号()括起来,单个元素括起来后加逗号(,)区分单个对象还是元组>>> T1 = ()>>> T2 = 1,2,3>>> T3 = 2,>>> print(type(T1),type(T2),ty...原创 2019-05-22 18:42:53 · 174 阅读 · 0 评论 -
python 复习之列表 list
列表定义: 1.列表中由一系列特定元素组成,元素与元素之间可能没有任何关联关系,但他们之间有先后顺序关系。 2.列表是一种序列 3.列表可以改变存储的各个元素 4.列表是一种容器列表的构造函数: list() 生成一个空列表,等同于[] list(iterable) 用可迭代对象初始一个列表列表的运算:算术运算符:+ +=...原创 2019-05-22 16:30:03 · 244 阅读 · 0 评论 -
python复习之字符串常用方法
假设字符串变量为S常用字符串的方法:S.isdigit() # 判断字符串是否全为数字>>> s1 = '123'>>> s2 = 'a123'>>> s1.isdigit()True>>> s2.isdigit()FalseS.isalpha() # 判断是否全英文字符>>>...原创 2019-05-22 15:12:19 · 146 阅读 · 0 评论 -
python复习之时间模块 time
时间模块:time 此模块提供了时间相关的函数,且一直可用。时间简介: 公元纪年:从0000年1月1日0时开始 计算机元年:从1970年1月1日0时开始,此时时钟为0 UTC(Coordinated Universal Time)是从Greenwich时间开始计算的 UTC时间不会因时区问题而产生错误时间元祖: 四位的年(如:19...原创 2019-05-24 16:10:04 · 145 阅读 · 0 评论