開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のII部(ビルトインオブジェクト)の9章(タプル、ファイルオブジェクト、その他)練習問題3、4を解いてみる。
その他参考書籍
練習問題3、4.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
import pickle
d = {'a':1,'b':2}
# wは書き込みモード bはバイナリーモード
with open('tmp', 'wb') as f:
pickle.dump(d, f)
# rは読み込みモード
with open('tmp', 'rb') as f:
data = pickle.load(f)
print(data)
# デフォルトの処理モードはr(読み込み)
with open('sample.py') as f:
print(f.read())
入出力結果(Terminal)
$ ./sample.py
{'a': 1, 'b': 2}
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
import pickle
d = {'a':1,'b':2}
# wは書き込みモード bはバイナリーモード
with open('tmp', 'wb') as f:
pickle.dump(d, f)
# rは読み込みモード
with open('tmp', 'rb') as f:
data = pickle.load(f)
print(data)
# デフォルトの処理モードはr(読み込み)
with open('sample.py') as f:
print(f.read())
$
0 コメント:
コメントを投稿