head first series 学习记录(Python)

来源:互联网 发布:linux不保存退出vi 编辑:程序博客网 时间:2024/06/04 19:40

1.缩进很重要

2.输入的时候需要加上引号

3.page 40

这样写不对。

import urllib2
page=urllib2.urlopen("http://www.beans-r-us.biz/prices.html")
text=page.read().decode("utf8")
print(text)

这样还是不对。

import urllib2
page=urllib2.urlopen('http://www.beans-r-us.biz/prices-loyalty.html')
text=page.read().decode('big5').encode('utf8')     //text=page.read().encode('utf8')

price=text[234:238]
print(price)

 

把网址换成可以正常访问的就okay。

4.page 57讲了一些方法。

5.twitter那个例子没有看。  ~page 1026

6.后面也没有看。 ~111

7.大概在page 153的这一段  

scores={}
scores[8.45]='Joseph'
scores[9.12]='Juan'
scores[7.21]='Zack'
for key in scores.keys():
    print(scores[key]+' had a score of '+str(name_part))
for score, suffer in scores.items():
    print(suffer+' had a score of '+str(score))
  运行不成功,我也不明白那个 name_part是什么意思。

 

 

 

            

注:

urllibPython 2 namePython 3 name
urllib.urlopen() Deprecated. See urllib.request.urlopen() which mirrorsurllib2.urlopen()
urllib.urlretrieve() urllib.request.urlretrieve()
urllib.urlcleanup() urllib.request.urlcleanup()
urllib.quote() urllib.parse.quote()
urllib.quote_plus() urllib.parse.quote_plus()
urllib.unquote() urllib.parse.unquote()
urllib.unquote_plus() urllib.parse.unquote_plus()
urllib.urlencode() urllib.parse.urlencode()
urllib.pathname2url() urllib.request.pathname2url()
urllib.url2pathname() urllib.request.url2pathname()
urllib.getproxies() urllib.request.getproxies()
urllib.URLopener urllib.request.URLopener
urllib.FancyURLopener urllib.request.FancyURLopener
urllib.ContentTooShortError urllib.error.ContentTooShortError

 

 

今天晚上看到page200,明天 come on!

0 0
原创粉丝点击