python学习记录

super用法

通过类的继承 子类访问父类的方法是可以调用

class base():
def kill(self):
print("base")
class ttt(base):
def w(self):
super().kill()

lambda 的用法
def xx():
print(2333)
x = lambda s: s+ 1
print(x)
x = lambda s: xx()
x(s)

# 装饰器的基本用法
def dec(func):
print('in dec')
return func

@dec
def test():
print('in test')

def params(a, b): 可换成 *a, **b
def dec(func):
print('begin')
func() # 调用被装饰的函数
print('end')
print(a,b)
return dec

@params(1,2)
def t():
print('test')

unicode_escape a.decode('unicode_escape') unicode('\u597d\u4eba')转中文 
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
isinstance 判断变量类型是否正确
isinstance(5,int) 返回TURE OR FALSE
或者使用 python schematics判断数据类型
获取文件路径 path = (os.path.dirname(__file__))
       os.listdir(os.path.join(path, 'xlsx')) # 当前文件的下级目录
       os.listdir(path)
       os.path.abspath # 路径转化(\保证在同一个方向)

需要pillow(python库) pytesser(python库), tesseract (安装程序)
im = Image.open("E:\\mypy\\1.jpg") # 简单图形验证码识别
imgry = im.convert('L') # 图像加强,二值化
sharpness = ImageEnhance.Contrast(imgry) # 对比度增强
sharp_img = sharpness.enhance(2.0)
sharp_img.save("E:\\mypy\\1.jpg")
print(pytesser3.image_file_to_string('E:\\mypy\\1.jpg'))

#python 读取ini文件
import configparser
config = configparser.ConfigParser()
config.read('email.ini', encoding='utf-8')
a = config.get('default', 'people')

posted on 2018-03-01 19:25  0o0o0o0o0o000  阅读(155)  评论(0编辑  收藏  举报

导航