01 2018 档案

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 阅读(179) 评论(0) 推荐(0)

代码这样写不止于优雅(2)
摘要: 阅读全文

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

代码这样写不止于优雅(1)
摘要: 阅读全文

posted @ 2018-01-07 16:24 chungehpu 阅读(103) 评论(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 阅读(109) 评论(0) 推荐(0)

super(classname,self).__init__() 作用
摘要: 阅读全文

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

if __name__ = "main" 解释
摘要: 阅读全文

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

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

posted @ 2018-01-07 14:45 chungehpu 阅读(99) 评论(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 阅读(101) 评论(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 阅读(246) 评论(0) 推荐(1)

导航