python:decorator

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
python:decorator [2011/06/19 22:50] – [引数を必要とするデコレータ] ともやんpython:decorator [2020/02/25 11:14] (現在) – [参考文献] ともやん
行 123: 行 123:
 <code python> <code python>
 # func_info(add) は _func_info を返すので # func_info(add) は _func_info を返すので
-# _func_info(1, 2)を実行しているのと等価+以下は _func_info(1, 2) を実行しているのと等価
 print func_info(add)(1, 2) print func_info(add)(1, 2)
 </code> </code>
行 224: 行 224:
     return _func_info     return _func_info
 </code> </code>
 + デコレータの引数(inc_docにTrue)を指定してデコレートする。
 <code python> <code python>
 # デコレートされた関数を定義 # デコレートされた関数を定義
行 248: 行 249:
  デコレータを関数として実行する場合、上記と等価なコードは以下のようになる。  デコレータを関数として実行する場合、上記と等価なコードは以下のようになる。
 <code python> <code python>
-# func_info(True) は __func_info を返すので +# func_info(True) は _func_info を返すので 
-# func_info(True)(add) は __func_info(add) と等価 +# func_info(True)(add) は _func_info(add) と等価 
-__func_info(add) は _func_info を返すので +_func_info(add) は __func_info を返すので 
-# 以下は _func_info(1, 2) を実行しているのと等価+# 以下は __func_info(1, 2) を実行しているのと等価
 print func_info(True)(add)(1, 2) print func_info(True)(add)(1, 2)
 </code> </code>
 ===== 参考文献 ===== ===== 参考文献 =====
-<html> +|<html> 
-<iframe src="http://rcm-jp.amazon.co.jp/e/cm?lt1=_blank&bc1=FFFFFF&IS1=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=tomoyan596-22&o=9&p=8&l=as1&m=amazon&f=ifr&ref=tf_til&asins=4048686291" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> +<a target="_blank"  href="https://www.amazon.co.jp/gp/product/4048930613/ref=as_li_tl?ie=UTF8&camp=247&creative=1211&creativeASIN=4048930613&linkCode=as2&tag=tomoyan.net-22&linkId=76a5d8652e69ddf7b93828d61c52b0b5"><img border="0" src="//ws-fe.amazon-adsystem.com/widgets/q?_encoding=UTF8&MarketPlace=JP&ASIN=4048930613&ServiceVersion=20070822&ID=AsinImage&WS=1&Format=_SL250_&tag=tomoyan.net-22" ></a><img src="//ir-jp.amazon-adsystem.com/e/ir?t=tomoyan.net-22&l=am2&o=9&a=4048930613width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> 
-</html>\\+</html>|<html> 
 +<iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&t=tomoyan.net-22&m=amazon&o=9&p=8&l=as1&IS2=1&detail=1&asins=4048930613&linkId=4991a49c3ce09cdb7570b40fe50a151c&bc1=ffffff&lt1=_top&fc1=333333&lc1=0066c0&bg1=ffffff&f=ifr"></iframe> 
 +</html>|
 [[http://www.python.jp/doc/2.6/library/functools.html|10.8. functools — 高階関数と呼び出し可能オブジェクトの操作 — Python v2.6.2 documentation]] [[http://www.python.jp/doc/2.6/library/functools.html|10.8. functools — 高階関数と呼び出し可能オブジェクトの操作 — Python v2.6.2 documentation]]
  • python/decorator.1308491436.txt.gz
  • 最終更新: 2019/05/18 02:23
  • (外部編集)