Head First Programming
A learner's guide to programming
using the Python language
( O'Reilly Media; )
David Griffiths (著) Paul Barry (著)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Programming A learner's guide to programming using the Python language (David Griffiths(著)、Paul Barry(著)、 O'Reilly Media; )のChapter 3(functions: Let's get organized)、Code Magnets(p.83)を解いてみる。
Code Magnets(p.83)
コード(BBEdit)
sample83.py
#!/usr/bin/env python3
#-*- coding: utf-8
import urllib.request
def getPrice():
page = urllib.request.urlopen(
'http://www.beans-r-us.appspot.com/prices.html')
text = page.read().decode('utf8')
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
print(text[start_of_price:end_of_price])
if __name__ == '__main__':
getPrice()
入出力結果(Terminal)
$ ./sample83.py 6.55 $
0 コメント:
コメントを投稿