栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何跳过或忽略python装饰器

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何跳过或忽略python装饰器

class a:    @HTMLwrapper    def return_stuff_as_html(self, input):        return self.return_stuff(input)    def return_stuff(self, input):        return awesome_dict

在等待响应时我做了同样的事情,对我来说很好,但是我仍然想知道是否还有更好的方法:) – olofom

由于在python中,函数和方法是对象,并且由于装饰器返回可调用对象,因此您可以在装饰后的方法上设置指向原始方法的属性,但是像my_object_instance.decorated_method.original_method()之类的调用将较丑陋且不太明确。

>>> import thisThe Zen of Python, by Tim PetersBeautiful is better than ugly.Explicit is better than implicit.Simple is better than complex.Complex is better than complicated.Flat is better than nested.Sparse is better than dense.Readability counts.Special cases aren't special enough to break the rules.Although practicality beats purity.Errors should never pass silently.Unless explicitly silenced.In the face of ambiguity, refuse the temptation to guess.There should be one-- and preferably only one --obvious way to do it.Although that way may not be obvious at first unless you're Dutch.Now is better than never.Although never is often better than *right* now.If the implementation is hard to explain, it's a bad idea.If the implementation is easy to explain, it may be a good idea.Namespaces are one honking great idea -- let's do more of those!


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/625752.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号