開発環境
- 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 4(Py Crust: Code Structures)、Things to Do 4.10.を解いてみる。
Things to Do 4.10.
コード(BBEdit)
sample10.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def test(func):
def new_function(*args, **kwargs):
print(func.__name__)
print('start')
result = func(*args, **kwargs)
print('end')
return result
return new_function
@test
def f(msg):
print(msg)
@test
def g(a, b):
return a if a > b else b
result = f('Hello, world!')
print(result)
result = g(5, 10)
print(result)
入出力結果(Terminal, IPython)
$ ./sample10.py f start Hello, world! end None g start end 10 $
0 コメント:
コメントを投稿