一开始没有创建类,直接使用函数的情况下,用如下写法运行是正常的:
def send_data(send_flag, name):
if send_flag:
send_data.__name__ = send_data.__name__ + ',' + "send_data_" + name
send_data.__name__ += ',' + "send_data" + name
后来修改为类,报错如下:
AttributeError: ‘method’ object has no attribute ‘name’
于是,做如下修改,解决问题:
将send_data.__name__修改为self.send_data.__func__.__name__
参考:
Dynamically changing a function name throws AttributeError: ‘method’ object has no attribute ‘name’