在python中,数组可以用list来表示。如果有两个数组,分别要求交集,并集与差集,怎么实现比较方便呢? 当然最容易想到的是对两个数组做循环,即写两个for循环来实现。这种写法大部分同学应该都会,而且也没有太多的技术含量, retA is: [3, 4, 5] retB is: [3, 4, 5] retC1 is: [1, 2, 3, 4, 5, 6, 7] retD is: [6, 7] retE is: [6, 7] 转自 http://blog.csdn.net/bitcarmanle ...
Read More »supervisor pkg_resources.DistributionNotFound: meld3>=0.6.5
换了台机器跑supervisor 突然报 pkg_resources.DistributionNotFound: meld3>=0.6.5 pip list meld3版本为1.02 最后从网上找到解决方案 修改 site-packages/supervisor-3.0-py2.6.egg-info/requires.txt 注释掉 #meld3 >= 0.6.5 问题解决
Read More »pymongo 聚合查询group
获取重复的手机号 db.weikephone.insert({“wid”:100000185, “phone”: 13818070900}) db.weikephone.insert({“wid”:100000186, “phone”: 13818070900}) db.weikephone.insert({“wid”:100000187, “phone” ...
Read More »python 解决 InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information
因为SSL的问题,urllib3需要pyopenssl。 最简单的方法是: pip install pyopenssl ndg-httpsclient pyasn1 还需要安装libffi-dev,libssl-dev 1.Ubuntu下安装 sudo apt-get install libffi-dev libssl-dev 2.CentOS下安装 yum install libffi-devel openssl-devel 参考地址 http://www.virson.cn/4465.htm ...
Read More »supervisord管理进程详解
Supervisor是由python语言编写,基于linux操作系统的一款服务器管理工具, 用以监控服务器的运行,发现问题能立即自动预警及自动重启等功能。 Supervisor类似于monit, monit和supervisor的一个比较大的差异是supervisor管理的进程必须由supervisor来启动, monit可以管理已经在运行的程序; supervisor还要求管理的程序是非daemon程序,supervisord会帮你把它转成daemon程序, 因此如果用supervisor来管 ...
Read More »python 中如何计算时间差
Q:如何方便的计算两个时间的差,如两个时间相差几天,几小时等 A:使用datetime模块可以很方便的解决这个问题,举例如下: 上例演示了计算两个日期相差天数的计算。 import datetime starttime = datetime.datetime.now() #long running endtime = datetime.datetime.now() print (endtime – starttime).seconds 上例演示了计算运行时间的例子,以秒进行显示。 上 ...
Read More »mac 安装MySQL-python EnvironmentError: mysql_config not found
1 locate mysql_config 找到mysql_config 2 将mysql_config的路径 添加到PATH中export PATH=$PATH:/Applications/XAMPP/xamppfiles/bin/mysql_config 3 pip install MySQL-python 参考 http://stackoverflow.com/questions/25459386/mac-os-x-environmenterror-mysql-config-not-fou ...
Read More »cookielib和urllib2模块相结合模拟网站登录
1.cookielib模块 cookielib模块的主要作用是提供可存储cookie的对象,以便于与urllib2模块配合使用来访问Internet资源。例如可以利用本模块的CookieJar类的对象来捕获cookie并在后续连接请求时重新发送。coiokielib模块用到的对象主要有下面几个:CookieJar、FileCookieJar、MozillaCookieJar、LWPCookieJar。其中他们的关系如下: 2.urllib2模块 说到urllib2模块最强大的部分绝对是它的ope ...
Read More »python实现定制交互式命令行
Python的交互式命令行可通过启动文件来配置。 当Python启动时,会查找环境变量PYTHONSTARTUP,并且执行该变量中所指定文件里的程序代码。该指定文件名称以及地址可以是随意的。按Tab键时会自动补全内容和命令历史。这对命令行的有效增强,而这些工具则是基于readline模块实现的(这需要readline程序库辅助实现)。 此处为大家举一个简单的启动脚本文件例子,它为python命令行添加了按键自动补全内容和历史命令功能。 $ cat .pythonstartup import re ...
Read More »python多线程模块threadpool简单使用
python实现线程池通常使用threading或thread模块来编写,现在已经有了threadpool模块来实现线程池。 英文文档见:http://www.chrisarndt.de/projects/threadpool/ 中文文档见:http://gashero.yeax.com/?p=44 现给出一个简易的使用threadpool模块来实现线程池的例子: 转自 http://dgfpeak.blog.51cto.com/195468/861994/
Read More »python中的Queue与多进程(multiprocessing)
一、先说说Queue(队列对象) Queue是python中的标准库,可以直接import 引用,之前学习的时候有听过著名的“先吃先拉”与“后吃先吐”,其实就是这里说的队列,队列的构造的时候可以定义它的容量,别吃撑了,吃多了,就会报错,构造的时候不写或者写个小于1的数则表示无限多 import Queue q = Queue.Queue(10) 向队列中放值(put) q.put(‘yang’) q.put(4) q.put([‘yan’,’xing’]) 在队列中取值get() 默认的队列是先 ...
Read More »nginx+flask+uwsgi 服务部署
最近学习python flask 参照教程做完blog后上线部署发现各种问题 在此记录下正确的安装流程 开发环境 ubuntu12.04 部署环境 centos6.4 打包上传解压后 一 按装python的包管理工具 yum install python-setuptools python-devel easy_install pip 二 安装 virtualenv虚拟环境 yum install python-virtualenv virtualenv env cd env/bin sourc ...
Read More »Python时间 日期 时间戳之间转换
1.将字符串的时间转换为时间戳 方法一: a = “2013-10-10 23:40:00″ #将其转换为时间数组 import time timeArray = time.strptime(a, “%Y-%m-%d %H:%M:%S”) #转换为时间戳: timeStamp = int(time.mktime(timeArray)) timeStamp == 1381419600 2.字符 ...
Read More »