有些任务,可能事先设置,时候做清理工作,如下面一段程序: f = open('tmp.txt') data = f.read() print(data) 是不是忘了什么?没错,很明显忘记关闭文件句柄.另外,对文件读取可能发生的异常在程序中没有做任何处理.下面使用 try except finally来处理, f = open('tmp.txt') try: data = f.read() print(data) except BaseException as msg: print(msg) fi
任何编程语言都有输入输出和用打交道,python也不例外,输入input(),输出print() 玖乐网络(http://www.96net.com.cn/)分享自己的心得 1,input()用法实例 name=input("please enter your name:") print("hello"+name) 2,print()用法实例 print("hello",name) print("hello"+name) p
1. Beautiful Soup 在它的官网有这样一段话: You didn't write that awful page. You're just trying to get some data out of it. Beautiful Soup is here to help. Since 2004, it's been saving programmers hours or days of work on quick-turnaround screen scraping project
from urllib import request import html.parser class zhuaqu(html.parser.HTMLParser): blogHtml = "" data = [] flag = 0 def getHtml(self): res = request.urlopen("http://www.cnblogs.com") self.blogHtml = res.read().decode('utf-8') def hand