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) 6.を解いてみる。
10.10(Exercises) 6.
コード(BBEdit)
sample6.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import time_series
def smallestValue(reader):
line = time_series.skipHeader(reader).strip()
if line != '':
smallest = int(line)
for line in reader:
value = int(line.strip())
if value >= smallest:
continue
smallest = value
return smallest
if __name__ == '__main__':
import sys
with open(sys.argv[1], 'r') as input_file:
print(smallestValue(input_file))
入出力結果(Terminal, IPython)
$ cat hopedale.txt
22
29
2
16
12
35
8
83
166
$ cat temp.txt
# header
$ ./sample6.py hopedale.txt
2
$ ./sample6.py temp.txt
None
$
0 コメント:
コメントを投稿