首页 > 编程语言 > 详细

python 装饰器3 robot源码@py2to3

时间:2021-04-06 16:51:13      阅读:25      评论:0      收藏:0      [点我收藏+]
  1. 定义
if PY2:
    # io.StringIO only accepts u‘foo‘ with Python 2.
    from StringIO import StringIO

    def py2to3(cls):
        if hasattr(cls, ‘__unicode__‘):
            cls.__str__ = lambda self: unicode(self).encode(‘UTF-8‘)
        return cls

else:
    from io import StringIO

    def py2to3(cls):
        if hasattr(cls, ‘__unicode__‘):
            cls.__str__ = lambda self: self.__unicode__()
        if hasattr(cls, ‘__nonzero__‘):
            cls.__bool__ = lambda self: self.__nonzero__()
        return cls
  1. 使用

@py2to3
class _BaseSettings(object):
    xxx

python 装饰器3 robot源码@py2to3

原文:https://www.cnblogs.com/amize/p/14622101.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!