2014年9月24日水曜日

開発環境

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) 2.を解いてみる。

10.10(Exercises) 2.

コード(BBEdit)

sample2.py

#!/usr/bin/env python3
#-*- coding: utf-8 -*-

alkaline_metals = []
with open('alkaline_metals.txt') as f:
    for line in f:
        alkaline_metals.append(line.split())

print(alkaline_metals)
for alkaline_metal in alkaline_metals:
    print(alkaline_metal)

入出力結果(Terminal, IPython)

$ ./sample2.py
[['beryllium', '4', '9.012'], ['magnesium', '12', '24.305'], ['calcium', '20', '20.078'], ['strontium', '38', '87.62'], ['barium', '56', '137.327'], ['radium', '88', '226']]
['beryllium', '4', '9.012']
['magnesium', '12', '24.305']
['calcium', '20', '20.078']
['strontium', '38', '87.62']
['barium', '56', '137.327']
['radium', '88', '226']
$

0 コメント:

コメントを投稿