2015年1月23日金曜日

開発環境

  • 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 7(Mangle Data Like a Pro)、Things to Do 7.6.を解いてみる。

Things to Do 7.6.

コード(Eacs, BBEdit)

sample6.py

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

letter = '''Dear {salutation} {name},

Thank you for your letter. We are sorry that our {product} {verbed} in your
{room}. Please note that it should never be used in {room}, especially
near any {animals}.

Send us your receipt and {amount} for shipping and handling. We will send
you another {product} that, in our tests, is {percent}% less likely to
have {verbed}.

Thank you for your support.

Sincerely,
{spokesman}
{job_title}'''

response = dict(salutation='s', name='n', product='p', verbed='v', room='r',
                animals='a', amount='a', percent='p', spokesman='s',
                job_title='j')
print(letter.format(**response))

入出力結果(Terminal, IPython)

$ ./sample6.py
Dear s n,

Thank you for your letter. We are sorry that our p v in your
r. Please note that it should never be used in r, especially
near any a.

Send us your receipt and a for shipping and handling. We will send
you another p that, in our tests, is p% less likely to
have v.

Thank you for your support.

Sincerely,
s
j
$

0 コメント:

コメントを投稿