開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python (プログラミング言語)
Head First Python (Paul Barry(著)、 O'Reilly Media )のChapter 3(Files and Exceptions: Dealing with errors)、EXERCISE(p.85)を解いてみる。
EXERCISE(p.85)
コード(BBEdit)
sample85.py
#!/usr/bin/env python3 #-*- coding: utf-8 with open('sketch.txt') as data: for each_line in data: if each_line.find(':') != -1: role, line_spoken = each_line.split(':', 1) print(role, end='') print(' said: ', end='') print(line_spoken, end='') # これでも、特定の場合に対処したにすぎない。 # 他の問題がでたら、また新たに対処する必要がある。
入出力結果(Terminal)
$ ./sample85.py Man said: Is this the right room for an argument? Other Man said: I've told you once. Man said: No you haven't! Other Man said: Yes I have. Man said: When? Other Man said: Just now. Man said: No you didn't! Other Man said: Yes I did! Man said: You didn't! Other Man said: I'm telling you, I did! Man said: You did not! Other Man said: Oh I'm sorry, is this a five minute argument, or the full half hour? Man said: Ah! (taking out his wallet and paying) Just the five minutes. Other Man said: Just the five minutes. Thank you. Other Man said: Anyway, I did. Man said: You most certainly did not! Other Man said: Now let's get one thing quite clear: I most definitely told you! Man said: Oh no you didn't! Other Man said: Oh yes I did! Man said: Oh no you didn't! Other Man said: Oh yes I did! Man said: Oh look, this isn't an argument! Other Man said: Yes it is! Man said: No it isn't! Man said: It's just contradiction! Other Man said: No it isn't! Man said: It IS! Other Man said: It is NOT! Man said: You just contradicted me! Other Man said: No I didn't! Man said: You DID! Other Man said: No no no! Man said: You did just then! Other Man said: Nonsense! Man said: (exasperated) Oh, this is futile!! Other Man said: No it isn't! Man said: Yes it is! $
0 コメント:
コメントを投稿