摘要: 1.安装,直接easy_install PILLOW 2.导入,from PIL import Image 阅读全文
posted @ 2017-04-26 12:32 水工 阅读(157) 评论(0) 推荐(0)
摘要: decode encode bytes >string >bytes decode('xxx'):将xxx转化成unicode encode('xxx'):将unicode转化成xxx 举例:百度,读取的文本乱码 con.text.encode('ISO-8859-1').decode('utf-8 阅读全文
posted @ 2017-04-26 11:30 水工 阅读(176) 评论(0) 推荐(0)
摘要: 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 阅读全文
posted @ 2017-04-25 19:21 水工 阅读(5909) 评论(0) 推荐(0)
摘要: 打开文件后,需要关闭文件:f.close() 直接用语句with...as...就可以不用再添加close()方法: with open(path,'w') as f: f.write(content) with open(path,'r') as f: f.readlines() 阅读全文
posted @ 2017-04-18 17:49 水工 阅读(2627) 评论(0) 推荐(0)
摘要: 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 阅读全文
posted @ 2017-04-06 17:44 水工 阅读(1471) 评论(0) 推荐(0)
摘要: 方法一:导入某一个模块 将模块(.py文件为一个模块)所在的目录加进来: import sys,os sys.path.append(path) import your_module 方法二:导入包下的所有模块 当前运行py文件下文件夹为package1 from package1 import * 阅读全文
posted @ 2017-04-05 17:26 水工 阅读(698) 评论(0) 推荐(0)
摘要: 1.当前目录: os.getcwd() 2.目录中包含内容: os.listdir(path) 3.是否为目录 os.path.isdir('E:\\book\\temp') 4.是否为文件 os.path.isfile('E:\\book\\temp') 5.把目录和文件名合成一个路径 os.pa 阅读全文
posted @ 2017-04-05 15:11 水工 阅读(1252) 评论(0) 推荐(0)
摘要: 将路径和文件名分开: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 阅读全文
posted @ 2017-03-31 17:41 水工 阅读(3359) 评论(0) 推荐(1)
摘要: 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 阅读全文
posted @ 2017-03-30 13:46 水工 阅读(139) 评论(0) 推荐(0)
摘要: 1.集合中元素是无序不重复的 2.可变集合定义set();不可变集合定义frozenset() 3.可变集合操作元素方法:add(),update(),remove() 4.集合定义,s=set(参数),参数可以为字符串、列表、字典(为字典时,得到的集合是字典键); 也可以直接定义,如s={1,'a 阅读全文
posted @ 2017-03-30 13:40 水工 阅读(182) 评论(0) 推荐(0)