随笔分类 - python
anaconda安装qt错误
摘要:windows下miniconda2安装python3下的qt包报错 conda install qt ERROR conda.core.link:_execute_actions(330): An error occurred while installing package 'defaults:
阅读全文
python获取路径
摘要:#!/usr/bin/env python import os #文件所在路径(模块路径) print __file__,os.path.realpath(__file__),os.path.abspath(__file__) #运行程序时所在路径 print os.path.curdir,os.path.realpath(os.path.curdir),os.path.abspath(os.p...
阅读全文
python-ldap
摘要:一、安装python-ldap找不到lber.h的解决方法sudo apt-get install libldap2-dev libsasl2-dev二、示例# coding=utf8import ldapsearchname='zzz'username='xxx'password='xxx'uid...
阅读全文
python splinter
摘要:firefox代理 driver:https://github.com/mozilla/geckodriver/releases chrome代理 driver:http://chromedriver.storage.googleapis.com/index.html https://sites.g
阅读全文
property
摘要:一、property用法property(fget=None, fset=None, fdel=None, doc=None) -> property attributefget is a function to be used for getting an attribute value, and...
阅读全文
pil
摘要:http://effbot.org/imagingbook/ 一、安装 pip install PIL --allow-external PIL --allow-unverified PIL 注:新版pip不支持--allow-external了,但可直接安装 pip install pillow
阅读全文
pynotify
摘要:1 import pynotify,sys2 if not pynotify.init('a'):3 sys.exit(1) 4 n=pynotify.Notification('title','info','file:///pathto/111.png')5 n.show()效果类似not...
阅读全文
python自我输出源程序
摘要:1、参考相应c程序1 s='s=%s%s%s;print s%s(chr(39),s,chr(39),chr(37))';print s%(chr(39),s,chr(39),chr(37))http://www.nyx.net/%7Egthompso/self_pyth.txt
阅读全文
python tkinter
摘要:1 import Tkinter2 top = Tkinter.Tk()3 top.mainloop()Tkinter的部件:Tkinter的提供各种控件,如按钮,标签和文本框,一个GUI应用程序中使用。这些控件通常被称为部件.目前有15种Tkinter的部件。我们提出这些部件以及一个简短的介绍,在...
阅读全文
python 正则表达式
摘要:import repattern=re.compile(fmt)m=pattern.match(str)或m=re.match(fmt,str)返回m.group() 所有匹配m.groups() 等价于[group(1),group(2),...],返回括号括起的分组>>> match = r...
阅读全文
python datatime
摘要:一、datetime 1、date date.today() 2、time 3、datetime datetime.datetime.now()/today() datetime.datetime.strftime(fmt) 转换为字符串 datetime.datetime.strptime(fmt
阅读全文
python命令行参数
摘要:〇、python中对应的argc, argv需要模块:sys参数个数:len(sys.argv)脚本名: sys.argv[0]参数1: sys.argv[1]参数2: sys.argv[2]一、getoptopts,args = getopt.getopt ( [命令行参数列表], "短选项", ...
阅读全文
安装uwsgi记录
摘要:yum install gccpip install uwsgi报错UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 ...解决:export LC_ALL=C报错:一堆c编译错解决:yum install python-devel
阅读全文
python profile
摘要:一、profile,cProfile1. python -m cProfile myprogram.pypython -m profile myprog.py2. 使用import profile模块import profiledef profileTest(): ...if __name__ =...
阅读全文
python多进程
摘要:一、多进程池 二、concurrent.future Python 3.2+concurrent.futures.wait(fs, timeout=None, return_when=ALL_COMPLETED):wait等待fs里面所有的Future实例(由不同的Executors实例创建的)完成
阅读全文
python读写xml
摘要:一、读取1、xml.dom.minidomimport xml.dom.minidomdoc=xml.dom.minidom.parse(file)#xml.dom.minidom.parseString(string)root=doc.documentElementfor node in root.childNodes: #print node,node.nodeName,node.nodeValue,node.nodeType #,node.data (for textnode) if node.nodeName=='channel': #and node.nodeType
阅读全文
python编码
摘要:1、#coding=utf8文本的字符编码s=u'xxxx'.encode('utf8')2、sys.getdefaultencoding,sys,setdefaultencoding转换缺省使用编码s.decode('utf8').encode('gbk')通常s.decode('utf8'),unicode也能正确输出3、sys.stdin.encoding,sys.stdout.encoding输出编码sys.stdout.encoding='gbk'改变标准输出流的编码方式的方法import
阅读全文
缓存 装饰器
摘要:def memoize(fn): stored_results = {} @functools.wrap(fn) def memoized(*args): try: # try to get the cached result return stored_results[args] except K
阅读全文
python备忘
摘要:1)列表逆序,字符串逆序l[::-1] l.reverse() #list2)三元操作符x if x>y else y(x>y and [x] or [y])[0]3)阶乘f=lambda n:reduce(lambda x,y:x*y,range(1,n+1))4)sort,sortedsorte
阅读全文
python使用sqlite
摘要:摘自python帮助文档一、基本用法import sqlite3conn = sqlite3.connect('example.db')#conn = sqlite3.connect(':memory:')c = conn.cursor()c.execute('''CREATE TABLE stocks (date text, trans text, symbol text, qty real, price real)''')#NULL,INTEGER,REAL,TEXT,BLOBc.execute("I
阅读全文
浙公网安备 33010602011771号