python代码输入怎么只能覆盖_如何防止函数在python中被覆盖

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-29 23:11   32   0

Is there a way to make a class function unoverriddable? something like java's final keyword. i.e, any overriding class cannot override that method.

解决方案

The issue is you are trying to write in Python using Java philosophies. Some thing carry over, but not all of them. In Python you can do the following and it is perfectly fine, but completely goes against how Java thinks of objects.

class Thing(object):

x = 1

something = Thing()

something.y = something.x

If you really want it, you can try the code posted here. But as you can see there is a lot of code there to get it to do what you want. It also should be noted that even the person that posted the code says it can be by passed using __dict__ or object.__setattr__.

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP