![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
柳暗花明又一村ヾ(◍°∇°◍)ノ゙
这个作者很懒,什么都没留下…
展开
-
python tkinter+ autohotkey更改键盘键位映射
tkinter autohotkey原创 2022-12-08 11:32:03 · 721 阅读 · 0 评论 -
python dwebsocket在django中使用
websocket原创 2022-07-14 15:35:46 · 533 阅读 · 0 评论 -
Django下载中文命名的文件解决方法
from django.http import JsonResponse, Http404,FileResponsedef download(request): with open(BASE_DIR + '\\static\\uploadfiles\\模板文件.xls', 'rb') as f: try: response =FileResponse(open(BASE_DIR + '\\static\\uploadfiles\\模板文件.xls', 'rb原创 2022-04-15 16:37:32 · 610 阅读 · 0 评论 -
python删除list中的元素
有三种方法,remove、pop、delll = ['a','b','c','d']ll.remove('a')llOut[26]: ['b', 'c', 'd']ll = ['a','b','c','d']ll.pop(1)Out[28]: 'b'llOut[29]: ['a', 'c', 'd']ll = ['a','b','c','d']del ll[0]llOut[32]: ['b', 'c', 'd']原创 2021-07-11 23:12:35 · 81 阅读 · 0 评论 -
python对数组排序并输出索引
主要用到numpy模块示例两种使用方式:import numpya = numpy.array([1,3,5,6,7])a.argsort()Out[4]: array([0, 1, 2, 3, 4], dtype=int64) array([1, 9, 5, 6, 7])numpy.argsort(a)Out[16]: array([0, 2, 3, 4, 1], dtype=int64)原创 2021-06-26 20:07:46 · 383 阅读 · 0 评论 -
python爬取李白和杜甫诗集,并处理,分类,预测
import reimport requestsimport jiebafrom bs4 import BeautifulSoup as bpfrom nltk.classify import NaiveBayesClassifier# 爬取李白和杜甫的诗集urls = ['https://so.gushiwen.org/authors/authorvsw_b90660e3e492A{}.aspx','https://so.gushiwen.org/authors/authorvsw_515e原创 2021-05-29 20:51:45 · 3121 阅读 · 0 评论 -
python爬取知乎网页图片
#!_*_coding:utf-8_*_from selenium import webdriverimport time, reimport urllib.request as reqfrom urllib.parse import quoteimport stringdriver = webdriver.Firefox()driver.maximize_window()driver.get('https://www.zhihu.com/question/29134042')#如果涉及原创 2021-05-29 20:46:57 · 161 阅读 · 0 评论 -
Django IntegerField设置取值范围
首先引入from django.core.validators import MaxValueValidator, MinValueValidator再设置;job = models.IntegerField(verbose_name='岗位专业',default=1,validators=[MaxValueValidator(100), MinValueValidator(1)])原创 2021-04-15 21:26:17 · 2773 阅读 · 0 评论 -
python numpy转list
只需用到一句命令tolist()import numpynumpy.array([1,3,5])Out[5]: array([1, 3, 5])a = numpy.array([1,3,5])a/3Out[7]: array([0.33333333, 1. , 1.66666667])a.tolist()Out[8]: [1, 3, 5]原创 2021-04-11 10:47:14 · 194 阅读 · 0 评论 -
django jsonresponse报错TypeError: In order to allow non-dict objects to be serialized set the safe par
输出的时候报错TypeError: In order to allow non-dict objects to be serialized set the safe parameter to False.这时候需要在JsonResponse中添加safe:return JsonResponse(json.dumps(Dict),safe=False)原创 2021-04-07 21:01:50 · 617 阅读 · 0 评论 -
django models增、删、改、查
查# 查询相关API:# <1>filter(**kwargs): 它包含了与所给筛选条件相匹配的对象# <2>all(): 查询所有结果# <3>get(**kwargs): 返回与所给筛选条件相匹配的对象,返回结果有且只有一个,如果符合筛选条件的对象超过一个或者没有都会抛出错误。#-----------下面的方法都是对查询的结果再进行处理:比如 objects.filter.values原创 2021-04-07 20:28:22 · 316 阅读 · 0 评论 -
python 格式化日期time
import timetime.strftime("%Y-%m-%d %H:%M:%S", time.localtime())Out[7]: '2021-03-31 02:48:51'time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()) Out[9]: 'Wed Mar 31 02:50:41 2021'# 将格式字符串转换为时间戳a = 'Wed Mar 31 02:50:41 2021'time.mktime(time.strpt原创 2021-03-31 10:53:40 · 113 阅读 · 0 评论 -
python pandas入门(2)
#_*_ coding: utf-8 _*_import numpy as npimport pandas as pdimport matplotlib.pyplot as pltdf = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar','foo', 'bar', 'foo', 'foo'], 'B': ['one', 'one', 'two', 'three','two', 'two', 'one', 'thre原创 2021-03-30 21:36:45 · 83 阅读 · 0 评论 -
ubuntu pip升级以后报错sys.stderr.write(f“ERROR: {exc}“)
apt-get remove --purge python-piprm -f /usr/local/bin/pipeasy_install pip==20.3.4ln -s /usr/local/bin/pip /usr/bin/pip原创 2021-03-23 09:59:57 · 1058 阅读 · 1 评论 -
python pandas入门(1)
#_*_ coding: utf-8 _*_import numpy as npimport pandas as pds= pd.Series([1,3,5,np.nan,6,8])dates = pd.date_range('20130101', periods=6)df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))#根据字典对象生成 DataFramedf2 = pd.DataFrame原创 2021-03-17 23:09:44 · 126 阅读 · 0 评论 -
python将pandas底层数据转numpy
主要使用to_numpy()df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD')) A B C D2013-01-01 -0.795050 -1.462931 -0.432862 -0.6215602013-01-02 0.831265 -1.166442 -0.783398 -0.6201672013-01-03原创 2021-03-16 22:49:23 · 1241 阅读 · 0 评论 -
python tkinter的简要应用
class Mygui(): def __init__(self): self.window = tk.Tk() screenwidth = self.window.winfo_screenwidth() screenheight = self.window.winfo_screenheight() x, y = int((screenwidth - 400) / 2), int((screenheight - 400) / 2)原创 2021-03-15 09:51:39 · 172 阅读 · 0 评论 -
pyinstaller打包folium相关项目
我的是在winx64位环境下,首先说一下pyinstaller打包项目的流程pythontaller -D xx.py 会生成xx.spec文件pyinstaller -w xx.spec参数意义:-F 打包单个文件,产生一个文件用于部署(默认),如果代码都写在一个.py文件时使用,项目有多个文件时不要使用-D 1.打包多个文件,产生一个目录用于部署(默认),用于框架编写的代码打包例:pyinstaller -D xxx.py(项目入口文件)例:pyinstaller --one原创 2021-03-15 09:12:48 · 383 阅读 · 0 评论 -
python list按第二个元素排序
主要用到key函数可以根据自己需求制定相应的key函数def takeSecond(elem): return int(elem)a = ['10000', '3000', '5000', '7000']a.sort(key = takeSecond)print(a)Out[13]: ['3000', '5000', '7000', '10000']原创 2021-03-13 19:40:08 · 1290 阅读 · 0 评论 -
python将字符串形式的列表转换成真实列表
主要用到json模块a ='[[45.5816,114.1634],[40.5816,104.1634],[39.5816,98.1634]]'import jsond = json.loads(a)d[0]Out[5]: [45.5816, 114.1634]原创 2021-03-12 16:50:40 · 169 阅读 · 0 评论 -
python opencv Kmeans聚类
使用Kmeans将图片颜色聚类import cv2import numpy as npimport matplotlib.pyplot as pltImg= cv2.imread('sunshine.jpg')img = cv2.cvtColor(Img,cv2.COLOR_BGR2RGB)Z = img.reshape((-1,3))z = np.float32(Z)criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITE原创 2021-03-01 23:03:37 · 238 阅读 · 0 评论 -
python将numpy多维数据转换成以为数组
使用ravel()a = np.array(np.random.randint(0,20,(15,2)))b = np.array(np.random.randint(0,2,(15,1))).astype(np.float32)#若果使用a[b==1]就会报错,使用ravel()转化成以为数组a[b.ravel()==1]Out[38]: array([[ 6, 4], [19, 1], [ 4, 6], [ 1, 4], [17原创 2021-02-28 10:54:12 · 989 阅读 · 0 评论 -
python beautifulsoup4解析网页
安装:pip install bs4pip install lxml引用:from urllib.request import urlopenfrom bs4 import BeautifulSoupr = urlopen('https://www.boc.cn/sourcedb/whpj/')response = r.read().decode('utf-8')soup = BeautifulSoup(response, features= 'lxml')常用的函数:搜索文档树,选原创 2021-01-30 20:19:59 · 168 阅读 · 0 评论 -
python将中文汉字转换成拼音
使用pinyin模块:pinyin.get()函数基本用法:pinyin.get(原文)可以返回对应的拼音字符(带有音标):pinyin.get('可以enable')kěyǐenablepinyin.get(原文,format = ‘strip’)可以返回对应的拼音字符(不带有音标):pinyin.get('可以enable',format = 'strip')keyienable...原创 2021-01-30 18:07:16 · 499 阅读 · 0 评论 -
python list类对象的常用方法
list类对象的常用方法a.append(x):将x作为心愿树天骄到列表末尾a.count(x):统计列表中有多少的值等于x.a.index(x):找出第一个等于x的元素,并返回下标a.insert(i,x):将x插入到列表中,下表为ia.pop(i):删除下标为i的元素,省略i,则删除最后一个元素。a.remove(i):删除列表中第一个等于i的元素。a.reverse():倒置列表a.sort()队列表排序。...原创 2021-01-30 14:43:16 · 217 阅读 · 0 评论 -
python 打开windows系统上的文件(音频、视频、记事本等)
直接适用os模块os.system在文件之前加starteg:os.system(r'start D:\tens\pyth\出击.wma')原创 2021-01-30 09:24:14 · 634 阅读 · 0 评论 -
python math模块功能详解
math.ceil(x)返回 x 的上限,即大于或者等于 x 的最小整数。如果 x 不是一个浮点数,则委托 x.ceil(), 返回一个 Integral 类的值。math.comb(n, k)返回不重复且无顺序地从 n 项中选择 k 项的方式总数。当 k <= n 时取值为 n! / (k! * (n - k)!);当 k > n 时取值为零。也称为二项式系数,因为它等价于表达式 (1 + x) ** n 的多项式展开中第 k 项的系数。如果任一参数不为整数则会引发 TypeErr转载 2021-01-30 08:45:34 · 934 阅读 · 0 评论 -
django uwsgi多进程运行
下载uwsgipip install uwsgi在djago项目下创建uwsgi.ini文件[uwsgi]#使用nginx连接时使用http = 0.0.0.0:8001#直接做web服务器使用#http=0.0.0.0:8000#项目目录chdir = /opt/newpro#项目中wsgi.py文件的目录,相当于项目目录wsgi-file = quene/wsgi.pyprocesses = 4threads = 2# 主进程master = True#pid文件, 用原创 2020-12-18 12:09:03 · 555 阅读 · 1 评论 -
python multiprocess报错: There is no current event loop in thread ‘Thread-1‘.
是因为函数中的循环时间导致:解决办法:pip install asyncio饭后在process的执行函数中添加:asyncio.set_event_loop(asyncio.new_event_loop())原创 2020-12-17 11:15:48 · 710 阅读 · 0 评论 -
python修改图片指定格式
from PIL import Imageimport osdef edit_image(path,oriangename,savename): im = Image.open(path + oriangename) im = im.resize((1100, 1450)) quality = 95 while 1: im.save(path + '已处理/' + savename,quality = quality, dpi = (144,144)原创 2020-12-03 22:09:22 · 278 阅读 · 0 评论 -
ubuntu 16.04环境下安装python3的libvirt
mv /usr/bin/python /usr/bin/pythonbakln -s /usr/bin/python3 /usr/bin/pythonapt-get install python3-pip libvirt-devpip3 install psutilwget https://files.pythonhosted.org/packages/6c/d4/207833148371d11478b258f3cbce1029c6352f599e0602cfd358618a84ad/libvirt原创 2020-12-02 09:56:30 · 728 阅读 · 0 评论 -
ubuntu16.04下devstack安装openstack
确保系统有pip,安装命令:apt-get install python-pippip install --upgrade pip配置pip加速 mkdir ~/.pip vim ~/.pip/pip.conf[global]index-url = http://pypi.douban.com/simple/ trusted-host = pypi.douban.com设置时间同步(1)设置时区:dpkg-reconfigure tzdata,选择Asia -->原创 2020-11-02 20:04:50 · 344 阅读 · 0 评论 -
python调用百度智能云api实现通用文字识别
首先登陆百度智能云网址https://console.bce.baidu.com/ai/?_=1602855861662#/ai/ocr/app/list获取APPID、API Key、Secret Key三个键值然后安装aip库:pip install baidu-aip==1.2.0.0识别指定目录下的的图形文件,输出文字# -*- coding: UTF-8 -*-from aip import AipOcrimport os# 定义常量APP_ID = '22832997'A原创 2020-10-16 22:44:14 · 953 阅读 · 0 评论 -
ImportError: No module named _internal.cli.main报错
ubuntu系统下报错Traceback (most recent call last): File "/usr/local/bin/pip3", line 7, in <module> from pip._internal.cli.main import mainImportError: No module named _internal.cli.main需要重新升级pippython -m pip install --upgrade pip...原创 2020-09-28 14:40:28 · 3748 阅读 · 0 评论 -
ubuntu安装python3.6
wget http://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz tar -xvzf Python-3.6.4.tgz cd Python-3.6.4 ./configure make make install报错:can't decompress data; zlib not available#执行apt-get install zlib*需要的话设置环境变量rm /usr/bin/pythonln -s /usr/lo原创 2020-09-04 08:24:00 · 110 阅读 · 0 评论 -
作业导入
import os#import threadingimport timeimport requestsfrom xml.dom.minidom import parseimport xml.dom.minidomimport jsonfrom urllib3 import encode_multipart_formdataimport shutilpath = "D:\Database\homework/"class HOMEWORK: files = [] file原创 2020-08-18 10:28:29 · 167 阅读 · 0 评论 -
python监控docker
import dockerimport subprocess#https://docker-py.readthedocs.io/en/stable/containers.htmlclass Dockermnage(): def __init__(self): self.client = docker.DockerClient(base_url='unix://var/run/docker.sock') # client = docker.from_env()原创 2020-07-23 23:57:10 · 732 阅读 · 0 评论 -
创建python虚拟环境
在ubuntu环境下apt-get install python-virtualenvpip install virtualenvvirtualenv myenv#创建虚拟环境myenv激活虚拟环境source bin/activate#退出虚拟环境deactivate原创 2020-07-23 10:00:09 · 131 阅读 · 0 评论 -
openstack python api
参考地址https://docs.openstack.org/mitaka/user-guide/sdk.html原创 2020-07-16 15:14:27 · 126 阅读 · 0 评论 -
windows运行软件隐藏控制台bat,
如果一个软件运行需要一直打开cmd窗口时在cmd上使用语句start /b auditbeat.exe做成自启动且不打开cmd控制台创建文件auditbeat.batC:cd C:Windows/system/auditbeatstart /b auditbeat.exe创建文件auditbeat.vbsSet shell = Wscript.CreateObject("WScript.Shell")a = shell.run ("C:/Windows/system/auditb原创 2020-07-09 17:27:40 · 550 阅读 · 0 评论