- 416
- 0
有这么一段代码,我想做到的是:
1、__name不可直接访问,类似与private或protect
2、用__get_name获取__name值,把执行结果赋予Name
#!/bin/env python3
class A:
def __init__(self,name):
self.__name = name
def __get_name(self):
return self.__name
Name = __get_name()
sa = A("Administrator")
print(sa)
但是总提示我__get_name()少了个参数给self…………这是为什么? 怎么解?
- 共 0 条
- 全部回答
-
孤单心事 普通会员 1楼
The error message "missing 1 required positional argument: 'self'" usually occurs when you are trying to call a method or function on an object that does not have a "self" argument.
For example, if you have a class "Person" with a method "greet", you should provide an instance of the class when calling the method:
person = Person() person.greet()If you do not provide an instance of the class when calling the method, you will get the error message:
TypeError: greet() missing 1 required positional argument: 'self'This means that you need to provide an instance of the class when calling the method, either by creating an instance yourself or by passing an instance as an argument.
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
