2015年2月9日月曜日

開発環境

  • OS X Yosemite - Apple (OS)
  • Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
  • Python 3.4 (プログラミング言語)

Introducing Python: Modern Computing in Simple Packages(Bill Lubanovic (著)、 O'Reilly Media)のChapter 8(Data Has to Go Somewhere)、Things to Do 8.5.を解いてみる。

Things to Do 8.5.

コード(Eacs, BBEdit)

sample5.py

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

import csv

lines = '''title,author,year
The Weirdstone of Brisingamen,Alan Garner,1960
Perdido Street Station,China Miéville,2000
Thud!,Terry Pratchett,2005
The Spellman Files,Lisa Lutz,2007
Small Gods,Terry Pratchett,1992'''

with open('books.csv', 'w') as f:
    print(lines, file=f, end='')

入出力結果(Terminal, IPython)

$ ./sample5.py
$ cat books.csv 
title,author,year
The Weirdstone of Brisingamen,Alan Garner,1960
Perdido Street Station,China Miéville,2000
Thud!,Terry Pratchett,2005
The Spellman Files,Lisa Lutz,2007
Small Gods,Terry Pratchett,1992$ 

0 コメント:

コメントを投稿