Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 10(Reading and Writing Files)、10.10(Exercises) 1.を解いてみる。
10.10(Exercises) 1.
コード(BBEdit)
sample1.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
name = input('ファイル名: ')
with open(name) as in_f, open(name + '.bak', 'w') as out_f:
for line in in_f:
out_f.write(line)
入出力結果(Terminal, IPython)
$ ./sample1.py
ファイル名: sample1.py
$ cat sample1.py.bak
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
name = input('ファイル名: ')
with open(name) as in_f, open(name + '.bak', 'w') as out_f:
for line in in_f:
out_f.write(line)
$
0 コメント:
コメントを投稿