
python
u010082526
这个作者很懒,什么都没留下…
展开
-
TypeError: Unicode-objects must be encoded before hashing
https://blog.youkuaiyun.com/haungrui/article/details/6959340使用过hashlib库的朋友想必都遇到过以下的错误吧:“Unicode-objects must be encoded before hashing”,意思是在进行md5哈希运算前,需要对数据进行编码。而且在不同版本的Python下还有所不同,唉Python还需努力啊,接口和消息都很不稳定。...转载 2018-07-16 14:43:35 · 16320 阅读 · 0 评论 -
codewars
地址:https://www.codewars.com/582789178yy80255681.注册‘sign up’2.选择语言 python3.答题(1)The code does not execute properly. Try to figure out why. 找出代码的错误def multiply(a, b): ...原创 2018-12-05 09:07:20 · 1539 阅读 · 0 评论 -
codewars练习(1)
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.本kata的目标是实现一个差异函数,该函数从一个列表减去另一个列表并返回结果。It should remove all values from l...原创 2018-12-05 09:49:31 · 697 阅读 · 0 评论 -
python循环数组下标
http://outofmemory.cn/code-snippet/3741/accessing-the-index-in-python-for-loops但是有时候我们会需要在便利数组的同时访问下标,这时候可以借助于enumerate函数来实现,例如:l = [1,2,3]for index,val in enumerate(l): print 'index is %d, v...原创 2018-12-05 10:21:59 · 4711 阅读 · 0 评论 -
python报错“must be str, not int”
for i in range(3): j=i+1 sqlstr=" insert into T_DATA_RISK(STATIONCODE,MONIDATE,RATE_PM25,RATE_NO2,STYLE)\ select a.id,a.recordtime,a.pm25/2...原创 2018-12-07 15:20:12 · 21370 阅读 · 0 评论 -
codewars练习(4)IP Validation
【1】计算字符串中包含字符个数n=txt.count('ab')参考https://jingyan.baidu.com/article/48b37f8dfda0581a646488dd.html【2】 is_valid_IP('a.255.56.1')报错ValueError: invalid literal for int() with base 10: 'a'解决方案:...原创 2018-12-17 10:58:03 · 369 阅读 · 0 评论 -
codewars练习(5)backwardsPrime--提交失败-Execution Timed Out (12000 ms)
【1】 li=list(string(a))NameError: name 'string' is not definedPython int与string之间的转化https://www.cnblogs.com/nzbbody/p/3581048.htmlstr(18)list(s ) 将序列 s 转换为一个列表 python...原创 2018-12-17 11:50:32 · 1629 阅读 · 0 评论 -
codewars练习(6)Sum of all the multiples of 3 or 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Finish the solution so that it returns the sum of all the multiples o...原创 2018-12-17 13:11:06 · 444 阅读 · 0 评论 -
python字符串截取
[('A1XY72CE03EB0710',)]for val in handID: print(val)('A1XY72CE03EB0710',) print(str(val)[1:-2])截取第一位(下标从0开始)到 倒数第二位之前'A1XY72CE03EB0710'参考https://www.cnblogs.com/xun...转载 2018-12-26 11:13:12 · 405 阅读 · 0 评论 -
python_flask(1)
1.pip install flask2.执行下面代码from werkzeug.wrappers import Request, Response@Request.applicationdef hello(request): return Response('Hello World!')if __name__ == '__main__': from werk...原创 2019-01-17 16:16:21 · 150 阅读 · 0 评论 -
python常见错误(1)TabError: inconsistent use of tabs and spaces in indentation
https://blog.youkuaiyun.com/Guopiqiang/article/details/73555898问题:Python文件运行时报TabError: inconsistent use of tabs and spaces in indentation原因:说明Python文件中混有Tab和Space用作格式缩进。这通常是使用外部编辑器编辑Python文件时,自动采用Tab进行...转载 2019-01-16 13:20:08 · 1422 阅读 · 0 评论 -
pythonweb(1)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler #导入HTTP处理相关的模块ModuleNotFoundError: No module named 'BaseHTTPServer'这里是涉及到python3和python2的语法区别,我的pywebsocket是python2版本的,但是Python却是py...原创 2019-01-16 14:29:12 · 262 阅读 · 0 评论 -
python模块整理(1)
1.seleniumfrom selenium import webdriverselenium自动化测试工具。它支持各种浏览器,包括 Chrome,Safari,Firefox 等主流界面式浏览器Selenium支持多种语言开发,比如 Java,C,Ruby,python等2.bs4from bs4 import BeautifulSoupBeautifulSoup是一种...原创 2018-11-22 10:16:20 · 132 阅读 · 0 评论 -
python读取sqlserver数据,并保存到csv中
# -*- coding: utf-8 -*-"""@use:查询17.11-18.1,18.6-18.8的PM2.5数据,导出到csv"""import pymssqlimport xlwtimport datetimefrom xml.dom.minidom import parse def do(): try: doc=parse('basein...原创 2018-11-12 16:10:25 · 6241 阅读 · 0 评论 -
python程序打包成exe
1.python安装pyinstaller cmd输入命令:pip install pyinstaller,安装成功后可看到,pyinstaller和pip在同一目录下(E:\ProgramData\Anaconda3\Scripts)2.Pyinstaller -F -p E:\Users\wangwei\Anaconda3 --hidden-import decimal...原创 2018-08-14 10:08:14 · 291 阅读 · 0 评论 -
python读取xml标签,if判断
1.xml里可以自定义标签 <timerange start="" end=""></timerange>2.读取标签 doc=parse('baseinfo.xml') timerange=doc.getElementsByTagName("timerange")[0] start=ti...原创 2018-08-14 14:21:43 · 2980 阅读 · 0 评论 -
python写sql换行,传递参数
sqlstr="insert into T_MON_AIRQUALITYHOUR (STATIONCODE, MONIDATE, PM25, NO2,TEMPERATURE,HUMIDITY) \ select STATIONCODE,'"+currentTime+"' MONIDATE,AVG(PM25) PM25,AVG(NO2) NO2, \ AVG(TEM...原创 2018-08-14 16:08:13 · 3081 阅读 · 0 评论 -
pyhon获取当前时间
nowtime=datetime.datetime.now().strftime("%Y%m%d%H")2018080214https://www.cnblogs.com/Jollyxi/p/8251977.htmlimport datetimenowTime=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')#现在past...转载 2018-08-02 14:18:13 · 262 阅读 · 0 评论 -
python里的decimal类型转换
https://blog.youkuaiyun.com/kebu12345678/article/details/54845908 [Python标准库]decimal——定点数和浮点数的数学运算 作用:使用定点数和浮点数的小数运算。 Python 版本:2.4 及以后版本 decimal 模块实现了定点和浮点算术运算符,使用的是大多数人所熟悉的模型,而...转载 2018-08-15 15:38:44 · 47419 阅读 · 0 评论 -
python里调用公共方法
需要调用到commaqi.py里计算AQI的方法commaqi里定义了公共类AqiCommon(class AqiCommon:)引入AqiCommonpm25_aqi=AqiCommon.getIAQI(pm25,'pm25')原创 2018-08-16 09:46:53 · 2180 阅读 · 0 评论 -
python里的round方法
四舍六入,五留双print(round(11.5))12print(round(10.5))10print(round(10.6))11print(round(11.4))11原创 2018-08-16 11:51:01 · 12589 阅读 · 1 评论 -
unsupported operand type(s) for *: 'float' and 'decimal.Decimal'
unsupported operand type(s) for *: 'float' and 'decimal.Decimal'co=round(co/2,3) co_aqi=AqiCommon.getIAQI(co,'co_hour')报错co_aqi=AqiCommon.getIAQI(0.3,'co_hour')可计算出IAQI值为3 float(round(co/2,2...原创 2018-08-16 13:58:37 · 10492 阅读 · 0 评论 -
python解析csv格式数据入库
【1】导入csv包import csv【2】读取csv文件路径def getExcelData(): try: csvx_list = glob.glob(r'F:\公司项目\2018年项目\中加app\数据\中加数据\校准数据\*.csv') print('总共发现%s个csv文件'% len(csvx_list)) return csvx_li...原创 2018-09-18 18:39:35 · 1913 阅读 · 0 评论 -
python批量修改文件名
# -*- coding: utf-8 -*-"""Created on Wed Nov 14 10:12:47 2018@author: Administrator"""import os #import pandas as pd#flagpath='F:/公司项目/2018年项目/中加app/数据/python导出excel数据表/健康风险数据/风险分析/2018年6月至8...转载 2018-11-14 10:38:15 · 309 阅读 · 0 评论 -
二叉树
作者丨IOExceptionerhttps://www.jianshu.com/p/0190985635eb 先上二叉树的数据结构: class TreeNode{ int val; //左孩子 TreeNode left; //右孩子 TreeNode right;} 二叉树的题目普遍可以用递归和迭代的方式来解1. 求...转载 2018-11-14 10:50:07 · 133 阅读 · 0 评论 -
Django安装配置
(1)如何用Python做Web开发?——Django环境配置(2)Python 集成开发环境,PyCharm 安装教程,包含注册码(3)pycharm安装教程(4)IntelliJ IDEA 注册码C:\Program Files\JetBrains\PyCharm 2018.3.5打开后,选择不导入配置文件...转载 2019-03-08 10:02:17 · 412 阅读 · 0 评论