关注@MisterMiyagi 评论(谢谢!),
我用(希望)更好/更短的例子重新表述我之前不清楚的问题。
在主脚本中, 我用 Class Exmaple 初始化 obj 。 我以 **kwargs 的身份通过了考试, 接下来,我调用该函数以使用 curr_test
来分配 self.test预期: self.test 将打印“测试” 实际的: 它不起作用,结果保持“测试”但它没有为 self.test 分配任何更改。
主要:
from my_class import example
obj = example(test = "")
obj._Test(obj.test)
print(len(obj.test))
# prints "0" expected "test"
类:
class example:
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
self.kwargs = kwargs
def _Test(self, curr_test = '' ):
curr_test = 'test'
print("curr_test :",curr_test ,"class test:",self.test)