随笔分类 - python相关
摘要:生成html报告: 1.安装nose(pip install nose) 2.安装nose_htmloutput 3.构建好的代码执行后在当前目录自动生成nosetests.html文件 4.网页访问该html文件 file:///path/nosetests.html 补充:1)主要是第二步安装;
阅读全文
摘要:报错“FileNotFoundError: [WinError 2] 系统找不到指定的文件”---win32 解决方法: 下载tesseract-ocr.exe安装,安装后将pytesseract.py(文件路径xxx\python34\Lib\site-packages\pytesseract\)
阅读全文
摘要:1.安装,直接easy_install PILLOW 2.导入,from PIL import Image
阅读全文
摘要:decode encode bytes >string >bytes decode('xxx'):将xxx转化成unicode encode('xxx'):将unicode转化成xxx 举例:百度,读取的文本乱码 con.text.encode('ISO-8859-1').decode('utf-8
阅读全文
摘要:1.安装tushare前先安装lxml和pandas(我是win32下python3.4.0) 2.安装lxml,下载地址https://pypi.python.org/pypi/lxml/3.4.2 3.pandas,下载地址https://pypi.python.org/pypi/pandas
阅读全文
摘要:打开文件后,需要关闭文件:f.close() 直接用语句with...as...就可以不用再添加close()方法: with open(path,'w') as f: f.write(content) with open(path,'r') as f: f.readlines()
阅读全文
摘要:import logging name=input() logging.basicConfig(filename=r'C:\Program Files\log.txt',datefmt='%Y-%m-%d %H:%M:%S %p',level=logging.DEBUG,format='%(asct
阅读全文
摘要:方法一:导入某一个模块 将模块(.py文件为一个模块)所在的目录加进来: import sys,os sys.path.append(path) import your_module 方法二:导入包下的所有模块 当前运行py文件下文件夹为package1 from package1 import *
阅读全文
摘要:1.当前目录: os.getcwd() 2.目录中包含内容: os.listdir(path) 3.是否为目录 os.path.isdir('E:\\book\\temp') 4.是否为文件 os.path.isfile('E:\\book\\temp') 5.把目录和文件名合成一个路径 os.pa
阅读全文
摘要:将路径和文件名分开:os.path.split() 分2中路径: 1.path='/abc/test/' import os os.path.split(path),得到元组('/abc/test','') 2.path='/abc/test' import os os.path.split(pat
阅读全文
摘要:1.表达式 for x in xx 如,list=[1,2,3,4,5]每项加1,得到新的列表 print([i+1 for i in list]) 2.表达式 for x in xx if语句 如,list=[1,2,3,4,5]对表现大于3的加1,得到新的列表 print([i+1 for i
阅读全文
摘要:1.集合中元素是无序不重复的 2.可变集合定义set();不可变集合定义frozenset() 3.可变集合操作元素方法:add(),update(),remove() 4.集合定义,s=set(参数),参数可以为字符串、列表、字典(为字典时,得到的集合是字典键); 也可以直接定义,如s={1,'a
阅读全文
摘要:1.创建test.py文件,如输入2个命令行参数,求和 #! python3 (windows下要加这行,但我没加也没报错) import sysa=sys.argv[1] #sys.argv列表的第一项(sys.argv[0])是文件名字符串,第二项是第一个命令行参数b=sys.argv[2] #
阅读全文
摘要:def f(x): return x*x a=map(f,[1,2,3])print(type(a)) #a的类型为mapb=map(lambda x:x*x,[1,2,3])print(list(b)) reduce(),对对象(列表,元组等)中的所有元素进行操作(先对第1、2个元素进行操作,得到
阅读全文
摘要:windows下: 1.下载openpyxl,http://pypi.doubanio.com/simple/openpyxl/ 2.将python根目录和/Scripts目录添加到环境变量PATH 3.cmd进入openpyxl解压文件夹,执行 pip install openpyxl 4.确认是
阅读全文
摘要:js弹框: 点击【确定】按钮,driver.switch_to_alert().accept() 点击【取消】按钮,driver.switch_to_alert().dismiss()
阅读全文
摘要:1.python3.x,打印为print() 2.python3.x,没有raw_input。input同raw_input()等效 3.python3.x,打印不换行print (i,end="") 4.当前系统时间:time.ctime() 5.调用其他路径下的模块 import sys sys
阅读全文
摘要:以连接postgresql为例: 1.安装psycopg2,下载地址:http://www.stickpeople.com/projects/python/win-psycopg/ 2.配置setting,具体内容略; 3.导入已有的数据库表,命令窗口的项目路径下输入:python manage.p
阅读全文

浙公网安备 33010602011771号