![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
Omghhhhhh
这个作者很懒,什么都没留下…
展开
-
python 读取excel文件(xls 和xlsx)的一些异常处理
常用的openpyl 只支持xlsx格式,对于xls格式文件会提示使用xlrd读取xls文件时,报错提示:_locate_stream(Workbook): seen0 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 320 2File "/usr/local/lib/python2.7/dist-packages/xlrd-0.9.4-py2.7.egg/xlrd/compdoc.py", line 418, in _locate_stream ra原创 2022-03-04 10:42:23 · 1923 阅读 · 1 评论 -
elasticsearch搜索引擎搭建
课程作业的简单记录。环境说明:操作系统:windows 10 Jdk:java 11 Elasticsearch 7.16.0 谷歌浏览器:97.0.4692.71(正式版本) (64 位)一、目标:1、淘宝抓取商品信息2、利用抓取的信息搭建搜索引擎二、设计方案1、爬虫:如下,提取淘宝网页中的商品文本信息:包括商品标题['title'],价格['price'],付款人数['nums'],店铺名称['name'],店铺地址['address'],保存到csv文件中2、.原创 2022-01-20 19:08:08 · 3099 阅读 · 0 评论 -
python中if和elif的区别
代码块中用 if 和 elif 的区别if:条件之间不相关,如果条件1判断成功的话,条件2也会继续判断。elif:条件之间相关,如果条件1判断成功的话,条件2就不会继续判断原创 2021-08-09 15:22:28 · 4268 阅读 · 0 评论 -
python 文件转base64
# python2.7import base64filepath = '11.pdf'with open(filepath, 'rb') as f1: base64_str = base64.b64encode(f1.read()) # str类型 print(base64_str) # JVBERi0xLjUNCiXi48/TDQo0IDAgb2JqDQ b'JVBERi0xLjUNCiXi48 # python3.6import base64fil...原创 2021-01-26 20:51:21 · 7014 阅读 · 0 评论 -
win7 内网重装pip
1、找到镜像下载pip包:/pipy/simple/pip/pip-9.0.2.tar.gz2、解压3、进入目录:python setup.py install原创 2020-12-31 11:26:36 · 162 阅读 · 0 评论 -
svg文件解析(python)
### 导入依赖包import xml.etree.ElementTree as etree# 打开文件tree = etree.ElementTree(file=r'/home/260190/PycharmProjects/auto_svgtopdf/test.svg') # 保证每次操作均为原始model文件root = tree.getroot()元素查找方法一、match为tag;不含嵌套,返回第一个/所有匹配的Element;可查找特定属性attrib[@id=“title1”]原创 2020-12-15 14:56:25 · 5654 阅读 · 3 评论 -
python 计算字符串长度(含中文)
txt = '名字12' lenTxt = len(txt) lenTxt_utf8 = len(txt.encode('utf-8')) size = int((lenTxt_utf8 - lenTxt)/2 + lenTxt) print("size = " , size ," ,urf8 = ",lenTxt_utf8," ,len = " ,lenTxt)一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函数取得的长度,进...原创 2020-10-20 11:13:44 · 13302 阅读 · 1 评论 -
pip install tex2svg
pip install tex2svg# for "inline mode" LaTeXecho "x^2" | tex2svg > x2.svg # for "block" LaTeXecho "x^2" | tex2svg --block > x2.svgDepends on pdflatex, pdfcrop, pdf2svg, and svgo. On Arch Linux, you can install these with:sudo pacman -S pd原创 2020-09-04 09:43:02 · 258 阅读 · 0 评论 -
anaconda 安装python3.7 自带虚拟环境
Anaconda python3.7相比以前的版本多了一个虚拟环境conda activate #激活虚拟环境,然后就看到,有一个base[root@medecineit ~]# conda activate(base) [root@medecineit ~]# pythonPython 3.7.3 (default, Mar 27 2019, 22:11:17) [GCC 7.3.0] :: Anaconda, Inc. on linuxType "help", "copyright原创 2020-08-26 13:45:09 · 1204 阅读 · 1 评论 -
python 开发android APP 简单小结
参考https://blog.csdn.net/qq_19582693/article/details/100598710一、kivy安装环境:python3.6、centos7.4官网下载安装:https://kivy.org/#download官网教程pdf:链接:https://pan.baidu.com/s/1TRvn034FJ2O1oi_qA2d22w 提取码:olbj以linux为例,https://kivy.org/doc/stable/installation/in..原创 2020-07-16 17:14:54 · 1601 阅读 · 0 评论 -
python字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1、字典dict = {'name': 'Zara', 'age': 7, 'class': 'First'}#字典转为字符串,返回:<type 'str'> {'age': 7, 'name': 'Zara', 'class': 'First'}print type(str(dict)), str(dict)#字典可以转为元组,返回:('age', 'name', 'class')print tuple(dict)#字典可以转为元组原创 2020-05-28 10:18:33 · 113 阅读 · 0 评论 -
python img2pdf 模块不能上传含alpha通道透明度的图片
官网说明pypi-img2pdfInput images with alpha channels are not allowed. PDF doesn’t support alpha channels in images and thus, the alpha channel of the input would have to be discarded. But img2pdf will always be lossless and thus, input images must not carry原创 2020-05-25 13:47:07 · 1498 阅读 · 0 评论 -
清华源pypi镜像使用
临时使用pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package设为默认升级 pip 到最新的版本 (>=10.0.0) 后进行配置:pip install pip -Upip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/...原创 2020-04-03 14:50:00 · 556 阅读 · 0 评论 -
opencv 2与3 关于cv2.findContours 轮廓检测区别
关于opencv 轮廓检测 中的 ValueError: too many values to unpack ,ValueError: not enough values to unpack (expected 3, got 2)Opencv2代码实现contours, hierarchy = cv2.findContours(binary,cv2.RETR_TREE,cv2.CHAIN_AP...原创 2020-04-03 10:01:19 · 536 阅读 · 0 评论 -
argparse.ArgumentParser()使用解析
参考:https://blog.csdn.net/the_time_runner/article/details/97941409官方:https://docs.python.org/zh-cn/3/library/argparse.html#prog原创 2020-01-02 15:20:41 · 1611 阅读 · 0 评论 -
python 计算汉明距离
两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目。两等长字符串的汉明距离:两字符串对应位置的不同字符的个数。python实现:def hamming(a, b): # compute and return the Hamming distance between the integers return bin(int(a) ^ int(b)).count("...原创 2019-12-27 16:52:57 · 8445 阅读 · 0 评论 -
centos7 python2和python3 共存
分别安装anaconda2 和anaconda3,安装路径选择/root/anaconda2 和 /root/anaconda3安装完成后,修改~/.bashrc文件,分别添加anaconda2、3的bin目录到PATH中,举例:export PATH="/home/anaconda2/bin:$PATH" export PATH="/home/anaconda3py36/bin:$PATH"...原创 2019-12-10 15:10:38 · 145 阅读 · 0 评论 -
Numpy的tile函数
https://www.jianshu.com/p/9519f1984c70原创 2019-12-02 16:01:47 · 235 阅读 · 0 评论 -
Jupyter noteboo配置 anaconda python编译器
安装完anaconda后Linux: 命令行输入 jupyter notebook,打开当前目录的网页生成配置文件:jupyter notebook --generate-configWindows: 1、进入C盘用户目录下,找到.jupyter 下的配置文件:jupyter_notebook_config.py,编辑其中的 C,NotebookApp.notebook_dir = u’D...原创 2019-12-01 16:16:28 · 924 阅读 · 0 评论 -
机器学习函数python代码实现
def sigmoid_activation(x, theta): x = np.asarray(x) theta = np.asarray(theta) return 1 / (1 + np.exp(-np.dot(theta.T, x)))原创 2019-11-20 11:09:34 · 131 阅读 · 0 评论 -
通用图像识别——百度API调用
基于python 2.7'''获取access_token'''import urllib, urllib2, sysimport ssl# client_id 为官网获取的AK, client_secret 为官网获取的SKhost = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&...原创 2019-06-03 09:33:55 · 2212 阅读 · 6 评论 -
python连接mysql
环境mysql 5.6python 2.7.14pymysql 0.9.2对象及方法Connection对象:用于建立与数据库的连接创建对象:调用connect()方法对象的方法close()关闭连接commit()事务,所以需要提交才会生效rollback()事务,放弃之前的操作cursor()返回Cursor对象,用于执行sql语句并获得结果Cursor对象:执行s...原创 2019-01-08 09:40:08 · 135 阅读 · 0 评论 -
获取numpy数组最大元素的索引
获取numpy数组最大元素a = np.arange(9).reshape((3,3))Out[4]: array([[0, 1, 2], [3, 4, 5], [6, 7, 8]])np.max(a) # 全局最大Out[5]: 8np.max(a,axis=0) # 每列最大Out[6]: array([6, 7, 8])np.max(a...原创 2019-03-07 16:56:41 · 12061 阅读 · 1 评论 -
获取numpy数组每列最高点行坐标
import numpy as npa = np.array([ [8, 1, 0, 8], [1, 4, 8, 8], [7, 8, 7, 6], [8, 7, 6, 5]])(rowa,cola)=np.where(a==np.max(a,axis=0)) # 每列最大元素的索引rowa=list(rowa)cola=list(...原创 2019-03-09 11:42:40 · 1087 阅读 · 0 评论 -
python排序函数
python 基础的排序函数 sort 、sorted 、argsort一、sort 、sorted1.简单升序排序直接调用sorted函数即可sort()方法仅定义在list中ls = list([5, 2, 3, 1, 4])ls.sort()print ls>>>[1, 2, 3, 4, 5]sorted()方法对所有的可迭代序列都有效,返回listl1...原创 2019-03-09 11:33:34 · 18137 阅读 · 1 评论 -
python去除列表中重复元素
速度快,但排序变化# set函数L = ['b','c','d','b','c','a','a'] set(L)Out[21]: {'a', 'b', 'c', 'd'}list(set(L))Out[22]: ['a', 'c', 'b', 'd']{}.fromkeys(l1).keys() Out[23]: ['a', 'c', 'b', 'd']保持原有排序# ...原创 2019-03-08 14:50:50 · 616 阅读 · 0 评论 -
python 中文unicode编码
python 中文unicode编码一、 excel中写入中文报错UnicodeDecodeError : ‘ascii’ codec can’t decode byte 0xe5 in position 0: ordinal not in range(128)解决方法:第一行加入 # -*- coding: utf-8 -*-,引用中文处使用unicode编码。代码如下:# -...原创 2019-03-20 19:18:20 · 12152 阅读 · 1 评论 -
python复制、移动文件到指定目录
import shutilshutil.copyfile(oldfile, newfile) # 复制shutil.move(oldfile, newfile) # 移动原创 2018-11-19 16:44:45 · 11786 阅读 · 0 评论 -
python unicode 转码问题详解
一、unicode与普通string字符串相互转换字符串在Python内部的表示是unicode编码,因此,在做编码转换时,通常需要 以unicode作为中间编码,即先将其他编码的字符串解码(decode)成unicode,再从unicode编码(encode)成另一种编码 。unicodestring = u&amp;quot;Hello world&amp;quot; 将普通Python字符串转化为Unicode:“de...原创 2018-11-19 15:23:08 · 4388 阅读 · 1 评论 -
flask将文件以base64编码格式返回前端
import base64path = '/home/a.pdf'f = open(path, 'rb')base64_str = base64.b64encode(f.read())print(base64_str)原创 2019-01-08 15:18:52 · 4063 阅读 · 2 评论 -
ocr字符识别安装 tesseract
1.配置源,对于CentOS 7,以root身份运行以下命令:yum-config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/sudo rpm --import https://build.opensuse.org/projects/home...原创 2019-04-01 19:02:17 · 961 阅读 · 0 评论 -
Python Console报错 :Couldn't connect to console process
问题:无法运行Python Console,提示Couldn’t connect to console process。ValueError: list.remove(x): x not in list解决方法:可能是装了python3.7的原因,更改setting 设置如下:将Python interpreter 改成了3.6Working directory 改到当前工作目录。...原创 2019-04-22 10:01:50 · 1183 阅读 · 0 评论 -
python字符串相关
str.rsplit()path = '/home/260190/PycharmProjects/文档内容修订检测/upload/20190610_14:50:35.154898/yansezhuanhuanf_0_result.html'path.rsplit('/', 2)Out[49]: ['/home/260190/PycharmProjects/文档内容修订检测/upload',...原创 2019-06-11 09:52:03 · 136 阅读 · 0 评论 -
centos+flask+unoconv报错
在 centos7.4 服务器上部署web服务,里面调用了 unoconv 命令,实现pdf 与 word 的转换。开启多线程时报错:1.未转换成PDF。但是unoconv没有报错,提示找不到文件,ERROR in app: Exception on /compare [POST]FileNotFoundError: [Errno 2] No such file or directory:...原创 2019-12-10 15:31:20 · 2265 阅读 · 0 评论 -
文字识别——百度API调用
基于python 2.7import urllib, urllib2, sys, base64import sslimport json'''获取access_token'''host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=【官网获取的AK】&a...原创 2019-06-03 09:45:04 · 690 阅读 · 0 评论 -
Python字符串格式化
字符串格式化,python有内置的‘%’、‘.format()函数等’格式符%s 字符串 (采用str()的显示)%r 字符串 (采用repr()的显示)%c 单个字符%b 二进制整数%d 十进制整数%i 十进制整数%o 八进制整数%x 十六进制整数%e 指数 (基底写为e)%E 指数 (基底写为E)%f 浮...原创 2019-06-03 09:17:46 · 123 阅读 · 0 评论 -
win7安装 python2 和 python3同时解决pip安装问题
一、anaconda python 版本对应关系python2.7.14 对应 Anaconda2-5.0.1python3.6 对应 Anaconda3-4.3.0二、下载anaconda镜像下载地址:清华镜像源官方下载地址:https://repo.anaconda.com/archive/三、安装anaconda点击下载的exe文件进行安装添加环境变量:C:\py...原创 2019-05-12 17:13:55 · 380 阅读 · 0 评论 -
python所有的标准异常类
异常名称 描述BaseException 所有异常的基类SystemExit 解释器请求退出KeyboardInterrupt 用户中断执行(通常是输入^C)Exception 常规错误的基类StopIteration 迭代器没有更多的值GeneratorExit 生成器(generator)发生异常来通知退出SystemExit Python 解释器请求退出StandardErr...原创 2019-05-16 10:15:30 · 135 阅读 · 0 评论 -
pdfplumber 提取 PDF 文本及表格
pdfplumber-0.5.12,适用于python 2.7、3.5、3.6.官网链接在此:https://github.com/jsvine/pdfplumber一、安装pip install pdfplumber二、使用提取文本:pdf.page[0].extract_text()提取表格:pdf.page[0].extract_tables()提取文字与表格(去除空格),分...原创 2019-12-10 15:32:04 · 3853 阅读 · 1 评论 -
python-flask-gunicorn-并发
python常见的web部署搭配nginx+gunicorn。gunicorn安装配置参数详解python多线程原创 2019-07-04 20:13:04 · 513 阅读 · 0 评论