2012年10月24日水曜日

開発環境

『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のII部(ビルトインオブジェクト)の9章(タプル、ファイルオブジェクト、その他)の練習問題3を解いてみる。

その他参考書籍

3.

処理モードのdefaultは読み込み(r)。

入出力結果(Terminal)

$ python
Python 3.3.0 (default, Sep 29 2012, 08:16:08) 
[GCC 4.2.1 Compatible Apple Clang 3.1 (tags/Apple/clang-318.0.58)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> file=open('sample.py')
>>> file.read()
'#!/usr/bin/env python3.3\n#-*- coding: utf-8 -*-\n\nd1 = {\'a\':0, \'b\':0}\nd2 = {}\nd2[\'a\'] = 0\nd2[\'b\'] = 0\n\nfor d in [d1, d2]:\n\tfor key, value in d.items():\n\t\tprint(key, "=>", value)\n\tprint()'
>>> file.write('test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
io.UnsupportedOperation: not writable
>>> quit()
$

書き込もうとするとエラーが発生する。

0 コメント:

コメントを投稿