
Python
huatian5
run
展开
-
pybind11 工具转换 C++ 接口
介绍pybind11 是一个轻量级的 header-only 库,可以将 C++ 类型暴露给 Python,反之亦然,主要用来将 C++ 接口转成 Python。安装apt install python3-devgit clone https://github.com/pybind/pybind11/git submodule update --init --recursive如果需要交叉编译 arm64 平台,会需要 aarch64-linux-gnu 中的头文件,可以改名或者下载构建原创 2020-10-17 13:34:35 · 673 阅读 · 1 评论 -
hackerrank Collections.deque()
题目:https://www.hackerrank.com/challenges/py-collections-deque/problem 题意:deque的基本操作 思路:基本操作 代码:'''-*- coding: utf-8 -*-@Author : PlayerGuan@Time : 2017/10/14 23:12@Software: PyCharm Communit原创 2017-11-10 21:26:35 · 243 阅读 · 0 评论 -
hackerrank Piling Up!
题目:https://www.hackerrank.com/challenges/piling-up/problem 题意:有点迷,大意就是是否从两边到中间逐渐减小 思路:list+sorted 代码:'''-*- coding: utf-8 -*-@Author : PlayerGuan@Time : 2017/10/14 23:12@Software: PyCharm Co原创 2017-11-10 22:15:54 · 325 阅读 · 0 评论 -
hackerrank Most Common
题目:https://www.hackerrank.com/challenges/most-commons/problem 题意:按照次数升序,次数相同降序 思路:s = sorted(Counter(input()).items(), key= lambda x: (-x[1],x[0]))[:3] 详细可见python dict sorted 排序 代码:'''-*- coding:原创 2017-11-10 22:51:26 · 326 阅读 · 0 评论 -
hackerrank itertools
题目:itertools.product()题意:所有的(a[],b[]) 思路:product用法 代码:from itertools import producta = map(int,input().split())b = map(int,input().split())print(*product(a,b))from itertools import producta = map原创 2017-11-13 12:27:04 · 292 阅读 · 0 评论 -
python list中append()与extend()用法
源地址 列表是以类的形式实现的。“创建”列表实际上是将一个类实例化。因此,列表有多种方法可以操作。 1. 列表可包含任何数据类型的元素,单个列表中的元素无须全为同一类型。 2. append() 方法向列表的尾部添加一个新的元素。只接受一个参数。 3. extend()方法只接受一个列表作为参数,并将该参数的每个元素都添加到原有的列表中。...转载 2018-03-16 15:38:35 · 393 阅读 · 0 评论 -
OpenCV VideoWriter用法
百度了一些,发现不对,在stackoverflow上面找到了解决方法,好像是版本问题 import cv2 path="......" file="......" videoCapture = cv2.VideoCapture(path) fps = videoCapture.get(cv2.CAP_PROP_FPS) width = vid...原创 2018-08-22 17:45:14 · 12240 阅读 · 0 评论 -
Python multiprocessing.Process
multiprocessing.Processmultiprocessing是python的中的一个多进程管理库,multiprocessing.Process模块用于创建进程使用方法:Process(target=, args=)target 要执行的函数传入函数的参数,必须是 iterable支持的函数:is_alive() 判断进程是否存活run() 创建进程未指定 ...原创 2018-12-01 00:12:58 · 1522 阅读 · 0 评论 -
Python 用法小结
一、指定解释器#!/usr/bin/python调用 /usr/bin/ 下的 python 解释器#!/usr/bin/env python自动去寻找 python 解释器(防止没有安装到 /usr/bin/ 目录的情况)二、限制版本if not sys.version_info[0] == 3: sys.exit(“only support python 3”)三、...原创 2019-08-15 21:28:09 · 188 阅读 · 0 评论 -
python2 升级 python3 的一些变化
sort 和 sortedpython2sort(cmp = _ _cmp_ _ (), key = None, reverse = False)cmp 参数为响应的比较函数,未指定默认调用 _ cmp _ ()(Should return a negative integer if self < other, zero if self == other, a positive...原创 2019-09-29 22:23:05 · 247 阅读 · 0 评论 -
hackerrank DefaultDict Tutorial
题目:https://www.hackerrank.com/challenges/defaultdict-tutorial/problem 题意:给你n个字符串,然后输入m个字符串ask,对于每个ask输出其位置 思路:defaultdict就相当于C++的map(怎么那么多类似的…),然后可以放各种东西,用来统计 如果访问不存在的key,会有KeyError 代码:'''-*- codi原创 2017-11-10 12:01:24 · 315 阅读 · 0 评论 -
hackerrank Word Order
题目:https://www.hackerrank.com/challenges/word-order/problem 题意:输入n个字符串,输出多少不同的字符串,并按照输入的顺序输出不同字符串的个数 思路:ordereddict存储,需要用到keys() 和values() 方法 代码:'''-*- coding: utf-8 -*-@Author : PlayerGuan@Time原创 2017-11-10 21:08:45 · 458 阅读 · 1 评论 -
PyCharm安装第三方模块Request、BeautifulSoup
开始用eclipse写python,然后还是不怎么好用,当初本地装了BeautifulSoup模块,eclipse里面也不能用,python自带IDLE也不是很好用,就又转PyCharm了。PyCharm里面安装这些模块可以选择,很简单,不用安装命令行什么的。 File->Settings->Project Interpreter 然后点“+” 输入要选择的库名,然后点击左下角的ins原创 2017-07-05 21:17:18 · 26315 阅读 · 6 评论 -
python导入第三方库
好像找到正确方法来,cmd先转入python位置,然后键入pip命令```cd /d G:\Pythonpip install twitter```看了一篇知乎的回答[https://www.zhihu.com/question/33646570/answer/193206961](https://www.zhihu.com/question/33646570/answer/193206961)发现要使原创 2017-07-09 23:25:39 · 996 阅读 · 0 评论 -
PyCharm设置模板添加默认信息
File->settings->Editor->Code Sytle->File and Code Templates选中Python Script原创 2017-08-17 11:44:03 · 2194 阅读 · 0 评论 -
Scrapy project 运行时出现no module named win32api 错误
出现这个错误的原因是Python中没有自带访问Windows系统api的库,要自己去下载安装下载https://sourceforge.net/projects/pywin32/files%2Fpywin32/ 在这个网站选择自己适合的文件,一般是选最新的吧? 然后选择文件下载,我的是Python3.5 32位 然后放到Python\Scripts目录中,cd Scripts ,然后输原创 2017-09-19 16:44:42 · 955 阅读 · 0 评论 -
Windows安装Scrapy库
本文参考http://blog.youkuaiyun.com/zjiang1994/article/details/526891441.安装wheel在控制台进入python位置,输入pip install wheel安装后查看是否安装成功(好像安装完就显示successful了) 输入wheel 如果安装成功会弹出一系列信息(一般都会成功),以下类似2.安装Twisted查看自己的配置: 在控制台进入p原创 2017-09-19 16:00:09 · 540 阅读 · 0 评论 -
Python网络爬虫笔记
Requests库Requests库中,encoding属性代表了从服务器返回HTTP协议头所推荐的编码方式,apparent_encoding属性代表了从服务器返回HTTP协议内容部分猜测的编码方式在Requests库的get()方法中,能够定制向服务器提交HTTP请求头的参数是headersResponse类的.content属性用于获取网络上某个URL对应的图片或视频等二进制资源raise_f原创 2017-08-11 14:32:42 · 584 阅读 · 0 评论 -
hackerrank collections.Counter()
题目:https://www.hackerrank.com/challenges/collections-counter/problem 题意:输入n,然后个袜子的尺寸,然后输入尺寸对应的价格,如果还有这种尺寸的,卖出得到收益 思路:Counter用来记录key出现的次数,类似C++的map 代码:'''-*- coding: utf-8 -*-@Author : PlayerGuan原创 2017-11-10 11:09:26 · 272 阅读 · 0 评论 -
hackerrank Collections.namedtuple()
题目:https://www.hackerrank.com/challenges/py-collections-namedtuple/problem 题意:给你n个学生的数据,算出平均成绩 思路:namedtuple是继承自tuple的子类,可以用Point = namedtuple('Point','x,y') 的方式创建一个Point类的对象,然后可以引用其属性 代码:'''-*- co原创 2017-11-10 11:39:58 · 276 阅读 · 0 评论 -
hackerrank Collections.OrderedDict()
题目:https://www.hackerrank.com/challenges/py-collections-ordereddict/problem 题意:按照输入的顺序统计每种物品的数量并输出 思路:defaultdict是混乱的,ordereddict是有序的dict,按照放入的顺序 代码:'''-*- coding: utf-8 -*-@Author : PlayerGuan@原创 2017-11-10 19:40:57 · 403 阅读 · 0 评论 -
正则表达式
不同语言的正则表达式可能会有些不同,这里写的是Python中的正则表达式。正则表达式常用符号“*” 表示前面的字符、子表达式或括号里的字符出现0次或多次“+” 表示前面的字符、子表达式或括号里的字符出现至少1次“[]” 匹配括号中的任意一个字符“()” 类似编程语言,有较高优先级“{m,n}” 表示前面的字符、子表达式或括号里的字符出现m~n次“[^]” 匹配任意一个不在中括号中的字符“|”原创 2017-07-04 11:00:07 · 264 阅读 · 0 评论