2018年1月7日

open的正确使用

摘要: open一个对象的时候,不确定他是图片还是文本啊 # import io with open('photo.jpg', 'rb') as inf: jpgdata = inf.read() if jpgdata.startswith(b'\xff\xd8'): text = u'This is a 阅读全文

posted @ 2018-01-07 16:50 chungehpu 阅读(155) 评论(0) 推荐(0) 编辑

代码这样写不止于优雅(2)

摘要: 阅读全文

posted @ 2018-01-07 16:33 chungehpu 阅读(61) 评论(0) 推荐(0) 编辑

代码这样写不止于优雅(1)

摘要: 阅读全文

posted @ 2018-01-07 16:24 chungehpu 阅读(96) 评论(0) 推荐(0) 编辑

一些基础语法

摘要: 1.使用 \ 将一行语句分为多行显示 statement = "hello world " + \ "this is my first time of creating blog in cnblogs " + \ "I am very excited" print(statement) output 阅读全文

posted @ 2018-01-07 15:42 chungehpu 阅读(105) 评论(0) 推荐(0) 编辑

super(classname,self).__init__() 作用

摘要: 阅读全文

posted @ 2018-01-07 15:04 chungehpu 阅读(660) 评论(0) 推荐(0) 编辑

if __name__ = "main" 解释

摘要: 阅读全文

posted @ 2018-01-07 14:49 chungehpu 阅读(130) 评论(0) 推荐(0) 编辑

ConfigParser 模块

摘要: Python 读取写入配置文件很方便,可使用内置的 configparser 模块 该模块支持读取windows 下的 .conf 及 .ini 文件等。 [section1] option1 = "hello" option2 = "world" [section2] option3 = 111 阅读全文

posted @ 2018-01-07 14:45 chungehpu 阅读(97) 评论(0) 推荐(0) 编辑

map + filter + reduce

摘要: map 是对 集合 里面的元素一个接一个的进行某种运算,常常与lambda 结合使用 #求平方: items = [1, 2, 3, 4, 5] squared = list(map(lambda x: x**2, items)) 此外,map还可以对函数进行迭代运算: # def multiply 阅读全文

posted @ 2018-01-07 14:31 chungehpu 阅读(98) 评论(0) 推荐(0) 编辑

requests + BeautifulSoup + json

摘要: requests: response.text 以 unicode 格式显示响应的文本 response.content 以 二进制 格式显示响应的文本 BeautiSoup: soup = BeautifulSoup (response.text,解析方式) 常用的解析方式有 "html.pars 阅读全文

posted @ 2018-01-07 13:25 chungehpu 阅读(238) 评论(0) 推荐(1) 编辑

导航