開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス: 限界を超える)、エクササイズ(p.417)をpythonで考えてみる。
エクササイズ(p.417)
コード(BBEdit, Emacs)
newshound.py
#!/usr/bin/env python3 #!/usr/bin/env python3 #-*- coding: utf-8 -*- import os import sys feeds = ["http://rss.cnn.com/rss/edition.rss", "http://rss.cnn.com/rss/edition_world.rss", "http://rss.cnn.com/rss/edition_africa.rss", "http://rss.cnn.com/rss/edition_americas.rss", "http://rss.cnn.com/rss/edition_asia.rss", "http://rss.cnn.com/rss/edition_europe.rss", "http://rss.cnn.com/rss/edition_meast.rss", "http://rss.cnn.com/rss/edition_us.rss"] phrase = sys.argv[1] for feed in feeds: env = dict(RSS_FEED=feed) try: os.execle('/usr/bin/python', '/usr/bin/python', 'rssgossip.py', phrase, env) except Exception as err: print(type(err), err)
入出力結果(Terminal, IPython)
$ ./newshound.py 'world' Zakaria: Is the world going nuts? World's most frustrating objects Are these the world's sexiest accents? Can the world stop Ebola? World's 15 best rivers for travelers $
0 コメント:
コメントを投稿