Python
yfraquelle
这个作者很懒,什么都没留下…
展开
-
Django02-项目配置
数据库在setting.py中,原来是DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), }}ENGINE:引擎,一般为'django.db.backends.sq原创 2017-09-05 18:21:28 · 202 阅读 · 0 评论 -
urllib3禁用警告
原文链接:https://www.cnblogs.com/xuchunlin/p/7607507.htmlInsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readth...转载 2018-11-06 17:57:32 · 3948 阅读 · 0 评论 -
python json.load UnicodeDecodeError: 'gbk' codec can't decode byte
原文链接:https://blog.csdn.net/u012052268/article/details/78106338 问题:使用 json.load()函数或者fp.read() 函数或者open()函数读取中文的时候,发现报错: UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xacUnicodeDecodeError: ...转载 2018-11-09 14:54:43 · 5122 阅读 · 0 评论 -
python中mongodb的list查询
这里topic_question中的topic_list是一个数组,需要查找topic_list中匹配给定两个元素的条目listf=list()results = db.topic_questions.find({'$and': [{'topic_list':source}, {'topic_list': target}]})for result in results: list...原创 2018-11-09 14:58:55 · 4029 阅读 · 0 评论 -
python list按照字典元素的某个key的值排序
newlist = sorted(list_to_be_sorted, key=lambda k: k['name']) 参考链接:https://stackoverflow.com/questions/72899/how-do-i-sort-a-list-of-dictionaries-by-a-value-of-the-dictionary原创 2018-11-09 15:02:50 · 4528 阅读 · 0 评论 -
python json utf-8乱码
原文链接:https://blog.csdn.net/celte/article/details/37820067 读取的json文件,然后输出后乱码。乱码均为\\u4e00\\u4e2a\\u7ea2\\u4eba\\u7684形式解决方案:data=json.load(file('test.json'))jsonobj=json.dumps(data, ensure_asci...转载 2018-11-09 15:45:19 · 4115 阅读 · 0 评论 -
Keras配置
vi $HOME/.keras/keras.json修改backend注意使用的python版本参考链接:https://stackoverflow.com/questions/47153429/how-to-change-the-backend-of-keras-to-theanohttps://stackoverflow.com/questions/43860033...原创 2018-11-02 15:02:24 · 145 阅读 · 0 评论 -
python3 urllib3发出网络请求时SSL: CERTIFICATE_VERIFY_FAILED
python3使用urllib3请求时出现SSL: CERTIFICATE_VERIFY_FAILED错误:安装安全模式:pip install requests[security]此时如果出现command 'x86_64-linux-gnu-gcc' failed with exit status 1错误:sudo apt-get install build-essential l...原创 2018-11-07 12:21:01 · 2610 阅读 · 0 评论 -
python的文件操作
原文链接:https://www.cnblogs.com/juandx/p/4962089.htmlpython中对文件、文件夹(文件操作函数)的操作需要涉及到os模块和shutil模块。得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd()返回指定目录下的所有文件和目录名:os.listdir()函数用来删除一个文件:os.remove()删除多个目...转载 2018-11-15 13:43:44 · 188 阅读 · 0 评论 -
python读写h5文件
原文链接:https://blog.csdn.net/leibaojiangjun1/article/details/53635353 h5接受的数据是矩阵跟mat方法一致,但是具有更强的压缩性能使用hdf5依赖于python的工具包:h5pyimport h5py #导入工具包import numpy as np#HDF5的写入:imgData = np.zeros((30,3...转载 2018-11-16 10:23:08 · 49098 阅读 · 11 评论 -
Python 读取wav格式文件
1、import wave 用于读写wav文件它提供了一个方便的WAV格式接口。但是不支持压缩/解压缩,支持单声道/立体声。读取格式:open(file[, mode])如果file是一个字符串,那么就打开文件,不然就把它当做一个类文件对象。mode是可以缺省的,如果输入的参数是一个类文件对象,那么file.mode将会作为mode的值。mode可选参数如下:'r', 'rb'...转载 2018-11-16 10:28:38 · 2411 阅读 · 2 评论 -
python抓取gb2312/gbk编码网页乱码问题
原文链接:https://blog.csdn.net/junli_chen/article/details/50082795 做了个网络爬虫抓取网页,但如果网页是gbk/gb2312编码,则会出现乱码问题,如下:取得文字后,直接打印,输出结果str如下:¹óÖÝÈËÊ¿¼ÊÔÐÅÏ¢Íø_¹óÖÝÈËÊ¿¼ÊÔÍø_¹óÖݹ«ÎñÔ±¿¼ÊÔÍø_¹óÖÝÖй«这个问题困扰我好...转载 2018-11-16 10:30:38 · 1846 阅读 · 0 评论 -
在mongodb中保存numpy数组
原文链接:https://cloud.tencent.com/developer/ask/32026对于一维numpy数组,可以使用列表:# serialize 1D array xrecord['feature1'] = x.tolist()# deserialize 1D array xx = np.fromiter( record['feature1'] )对于多维数...转载 2018-11-16 10:33:01 · 1844 阅读 · 0 评论 -
python HTTPSConnectionPool(host='rapzh.coms', port=443)
python请求https出现这种错误requests.exceptions.ConnectionError: HTTPSConnectionPool(host='rapzh.coms', port=443): Max retries exceeded with url:......需要加上参数verify=Falseresponse = requests.get(url,verif...转载 2018-11-16 10:52:44 · 3835 阅读 · 0 评论 -
Python urlencode和urldecode
原文链接:https://blog.csdn.net/qq_39377696/article/details/80454950 在Python3中,将中文进行urlencode编码使用函数urllib.parse.quote(string, safe='/', encoding=None, errors=None)而将编码后的字符串转为中文,则使用urllib.parse.u...转载 2018-11-16 12:32:45 · 487 阅读 · 0 评论 -
python 批量将列表元素转换为数字
原文链接:https://www.jb51.net/article/86561.htm本文实例讲述了Python中列表元素转为数字的方法。分享给大家供大家参考,具体如下:有一个数字字符的列表: 1 numbers = ['1', '5', '10', '8'] 想要把每个元素转换为数字: 1 numbers = [...转载 2018-12-14 18:29:54 · 27566 阅读 · 4 评论 -
python 移动、复制文件
原文链接:https://blog.csdn.net/seanblog/article/details/78885423https://docs.python.org/3.6/library/shutil.htmlshutil可以实现文件的复制,移动#复制文件:shutil.copyfile("oldfile","newfile") #oldfile和newfile都只能是文...转载 2019-03-23 11:50:35 · 7500 阅读 · 0 评论 -
python操作mongodb
原文链接:https://www.cnblogs.com/melonjiang/p/6536876.html下载python中MongoDB的驱动程序pip install pymongo然后确保MongoDB已经安装且可以正常运行,去官网下载相应版本:https://www.mongodb.com/mkdir -p /home/toolscd/home/toolswget...转载 2018-11-06 17:56:26 · 125 阅读 · 0 评论 -
python的urllib3
原文链接:https://www.cnblogs.com/KGoing/p/6146999.html Urllib3是一个功能强大,条理清晰,用于HTTP客户端的Python库,许多Python的原生系统已经开始使用urllib3。Urllib3提供了很多python标准库里所没有的重要特性: 1、 线程安全 2、 连接池 ...转载 2018-11-06 17:53:53 · 3208 阅读 · 0 评论 -
python的网络请求
原文链接:https://www.jianshu.com/p/f05d33475c78urllib是Python中请求url连接的官方标准库,在Python2中主要为urllib和urllib2,在Python3中整合成了urllib。而urllib3则是增加了连接池等功能,两者互相都有补充的部分。urlliburllib作为Python的标准库,基本上涵盖了基础的网络请求功能。...转载 2018-11-06 17:50:56 · 2119 阅读 · 0 评论 -
Django01-安装和示例
环境Windows10python 3pip install Django==1.11.4验证import djangoprint(django.get_version())创建项目django-admin startproject HelloWorld项目结构.|-- HelloWorld| |-- __init__.py| |原创 2017-09-05 15:11:05 · 376 阅读 · 0 评论 -
Django03-model
以一个积分系统作为示例创建模型首先在app中修改models.py定义两个模型User和Pointsfrom django.db import modelsclass User(models.Model): id=models.indexes username=models.CharField(max_length=200) password=models.原创 2017-09-07 11:56:53 · 221 阅读 · 0 评论 -
Django05-表单
我们增加如下页面:/points/edit/ 添加积分页面(填写提交后跳转积分详情页面)views.pydef edit(request,user_id): user=get_object_or_404(User,pk=user_id) # 直接使用get_object_or_404来处理,调用get() return render原创 2017-09-07 18:14:54 · 174 阅读 · 0 评论 -
Django04-view
根据之前数据库中实体的关系,我们相应建立几个view/points 首页,显示不用模板的用户列表/points/help 帮助页,显示不用模板的固定返回值/points/notice 通知页,显示使用模板的用户列表/p原创 2017-09-07 17:29:02 · 331 阅读 · 0 评论 -
Django06_model field
一个Model通常是一个python的django.db.models.Model类的子类,对应于一个数据库表。Model中的每一个属性表示一个数据库字段。定义模型后需要将app的名称写入manage.py的INSTALLED_APPS中,这样才能使用模型。基本的Model创建已经在前面说过,运行manage.py migrate,Django会在数据库中自动创建一个appname_mod原创 2017-09-11 17:45:00 · 320 阅读 · 0 评论 -
python requests解析
原文链接:http://blog.csdn.net/junli_chen/article/details/53670887一个http请求包括三个部分,为别为请求行,请求报头,消息主体,类似以下这样:请求行 请求报头 消息主体HTTP协议规定post提交的数据必须放在消息主体中,但是协议并没有规定必须使用什么编码方式。服务端通过是根据请求头中的Content-Type字转载 2017-08-07 19:44:41 · 424 阅读 · 0 评论 -
python bytes to string
b"qwert".decode("utf-8)原创 2018-03-31 21:18:27 · 5080 阅读 · 0 评论 -
pip用国内镜像下载
原文链接:原文:https://blog.csdn.net/u010536377/article/details/50564185 异常信息:Retrying (Retry(total=2, connect=None, read=None, redirect=None)) after connection broken by ‘ReadTimeoutError(“HTTPSConnecti...转载 2018-10-23 00:31:39 · 514 阅读 · 0 评论 -
numpy where()函数
原文链接:https://blog.csdn.net/qq_32005671/article/details/74011993numpy.where()函数是三元表达式x if condition else y的矢量化版本。假设我们有一个布尔数组和两个值数组:x = np.array([1.1, 1.2, 1.3, 1.4, 1.5])y = np.array([2.1, 2.2, 2....转载 2018-10-28 19:29:19 · 242 阅读 · 0 评论 -
python的时间转换问题
time模块:import time字符串转时间戳:timestring = '2016-12-21 10:22:56'time.mktime(time.strptime(timestring, '%Y-%m-%d %H:%M:%S')) # 1482286976.0时间戳转字符串:timestamp = time.time()timestruct = time.local...原创 2018-10-29 15:20:17 · 518 阅读 · 0 评论 -
将Numpy数组保存为图像
原文链接:https://blog.csdn.net/xijuezhu8128/article/details/79661016有一个Numpy数组类型的矩阵,如何将它作为图像写入磁盘?任何格式的图像都行(PNG,JPEG,BMP ...)。 最佳解决办法可以使用scipy.misc,代码如下: import scipy.misc scipy.misc.i...转载 2018-10-26 14:23:04 · 2361 阅读 · 0 评论 -
python导入自定义模块
原文链接:http://www.cnblogs.com/ylan2009/p/4186768.html对于python2.7:1.如果导入的模块和主程序在同个目录下,直接import就行了2.如果导入的模块是在主程序所在目录的子目录下,可以在子目录中增加一个空白的__init__.py文件,该文件使得python解释器将子目录整个也当成一个模块,然后直接通过“import 子目录.模块...转载 2018-10-26 14:25:26 · 140 阅读 · 0 评论 -
Python报错segmentation fault
内存不足参考链接:https://stackoverflow.com/questions/10035541/what-causes-a-python-segmentation-fault转载 2018-10-26 14:26:59 · 14621 阅读 · 0 评论 -
升级pip后出现ImportError: cannot import name main
原文链接:https://blog.csdn.net/accumulate_zhang/article/details/80269313在Ubuntu中,升级了pip,再次使用pip 安装相关的python包的时候就出现以下错误ImportError: cannot import name main解决:pip文件在usr/bin目录下,cd进去,进行以下修改把下面的三行from...转载 2018-10-26 16:33:53 · 236 阅读 · 0 评论 -
python3中bytes与string的互相转换
原文链接:http://www.cnblogs.com/txw1958/archive/2012/08/31/python3-bytes-string.html首先来设置一个原始的字符串,Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copy...转载 2018-10-30 11:43:01 · 419 阅读 · 0 评论 -
python去字符串空格
原文链接:https://blog.csdn.net/zhangfengwusha/article/details/28389853 字符串里有三个去空格的函数strip 同时去掉左右两边的空格lstrip 去掉左边的空格rstrip 去掉右边的空格>>>a=" gho stwwl ">>>a.lstrip()'gho stwwl '>...转载 2018-10-30 11:43:46 · 684 阅读 · 0 评论 -
numpy数组精确保存为图片的方法
发现用cv2.write、scipy.misc.imsave、scipy.misc.toimage().save()保存都有细微的偏差,最终用PIL.Image.fromarrya().save()才能精确地将值保存下来参考链接:https://www.cnblogs.com/skyfsm/p/8276501.html...原创 2019-04-08 14:09:23 · 3329 阅读 · 6 评论