首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将代码从C+转换为Python?

如何将代码从C+转换为Python?
EN

Stack Overflow用户
提问于 2018-06-13 07:14:40
回答 2查看 0关注 0票数 0

我需要将这部分代码从C+转换为Python2.7。怎么做?

代码语言:txt
复制
#define RED_MAX 255
EN

Stack Overflow用户

发布于 2018-06-13 16:45:14

代码语言:txt
复制
    # Put in const.py...:
class _const:
    class ConstError(TypeError): pass
    def __setattr__(self,name,value):
        if self.__dict__.has_key(name):
            raise self.ConstError, "Can't rebind const(%s)"%name
        self.__dict__[name]=value
import sys
sys.modules[__name__]=_const()

# that's all -- now any client-code can
import const
# and bind an attribute ONCE:
const.magic = 23
# but NOT re-bind it:
const.magic = 88      # raises const.ConstError
# you may also want to add the obvious __delattr__
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档