開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Python 3.5 (プログラミング言語)
Exercises for Programmers: 57 Challenges to Develop Your Coding Skills (Brian P. Hogan 著、Pragmatic Bookshelf)のChapter 8(Working with Files)、45(Word Finder)を取り組んでみる。
45(Word Finder)
コード(Emacs)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- filename_in = "sample45.txt" filename_out = input('the name of the output file: ') with open(filename_in) as in_f, open(filename_out, 'w') as out_f: for line in in_f: line = line.replace('utilize', 'use') print(line, file=out_f, end='')
入出力結果(Terminal, IPython)
$ ./sample45.py the name of the output file: sample45.out $ cat sample45.out One should never use the word "use" in wrting. Use "use" instead. $
0 コメント:
コメントを投稿