開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語: Python
『初めてのPython 第3版』(Mark Lutz 著、夏目 大 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-393-7) のVI部(オブジェクト指向プログラミング)25章(クラスの設計)の練習問題2を解いてみる。
その他参考書籍
2.
コード(BBEdit)
sample.py
#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-
class A:
def __init__(self, object):
self.data = object
def __getattr__(self, name):
print("Trace: {0}".format(name)) # 自身にも機能を持たせる
return getattr(self.data, name) # 組み込まれた他のオブジェクトに処理を委譲
a = A([1,2,3,4,5])
for x in range(6, 11):
a.append(x)
print(a.pop())
print(a.index(1))
print(a.count(2))
print(a.sort())
print(a.reverse())
print(a.data)
入出力結果(Terminal)
$ ./sample.py Trace: append Trace: append Trace: append Trace: append Trace: append Trace: pop 10 Trace: index 0 Trace: count 1 Trace: sort None Trace: reverse None [9, 8, 7, 6, 5, 4, 3, 2, 1] $
0 コメント:
コメントを投稿