開発環境
- 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 #-*- 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: pid = os.fork() except Exception as err: print(type(err), err) else: if pid != 0: try: os.execle('/usr/bin/python', '/usr/bin/python', 'rssgossip.py', phrase, env) except Exception as err: print(type(err), err)
入出力結果(Terminal, IPython)
$ cp newshound.py old_newshound.py $ ./old_newshound.py 'world' World's weirdest plane turns 20 Zakaria: Is the world going nuts? World's most frustrating objects World's strangest-looking plane turns 20 Are these the world's sexiest accents? Can the world stop Ebola? World's 15 best rivers for travelers $ ./newshound.py 'world' Building the world's tallest tower Post-9/11 world of threats World's biggest record collection World-class Caribbean carnival And the world's busiest airport is ... The world's sexiest accents Spreading ethio-jazz to the world The world of Somalian literature Can this school save the world? CNN.com - World CNN.com - World What's the world's sexiest accent? World's weirdest plane turns 20 Zakaria: Is the world going nuts? World's most frustrating objects World's strangest-looking plane turns 20 Are these the world's sexiest accents? Can the world stop Ebola? World's 15 best rivers for travelers $
0 コメント:
コメントを投稿