好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

docstring show under decorator

docstring show under decorator

http://stackoverflow测试数据/questions/3865254/about-python-doc-docstring/3865321#3865321

functools. wraps ( wrapped [ , assigned ] [ , updated ] ) ?

This is a convenience function for invoking partial(update_wrapper, wrapped=wrapped, assigned=assigned, updated=updated) as a function decorator when defining a wrapper function. For example:

 >>>   from   functools   import   wraps 
 >>>   def   my_decorator  (  f  ): 
 ...       @wraps  (  f  ) 
 ...       def   wrapper  (  *  args  ,   **  kwds  ): 
 ...           print   'Calling decorated function' 
 ...           return   f  (  *  args  ,   **  kwds  ) 
 ...       return   wrapper 
 ... 
 >>>   @my_decorator 
 ...   def   example  (): 
 ...       """Docstring""" 
 ...       print   'Called example function' 
 ... 
 >>>   example  () 
 Calling decorated function 
 Called example function 
 >>>   example  .  __name__ 
 'example' 
 >>>   example  .  __doc__ 
 'Docstring' 

Without the use of this decorator factory, the name of the example function would have been 'wrapper' , and the docstring of the original example() would have been lost.

查看更多关于docstring show under decorator的详细内容...

  阅读:53次

CopyRight:2016-2025好得很程序员自学网 备案ICP:湘ICP备09009000号-16 http://haodehen.cn
本站资讯不构成任何建议,仅限于个人分享,参考须谨慎!
本网站对有关资料所引致的错误、不确或遗漏,概不负任何法律责任。
本网站刊载的所有内容(包括但不仅限文字、图片、LOGO、音频、视频、软件、程序等)版权归原作者所有。任何单位或个人认为本网站中的内容可能涉嫌侵犯其知识产权或存在不实内容时,请及时通知本站,予以删除。

网站内容来源于网络分享,如有侵权发邮箱到:kenbest@126.com,收到邮件我们会即时下线处理。
网站框架支持:HDHCMS   51LA统计 百度统计
Copyright © 2018-2025 「好得很程序员自学网
[ SiteMap ]