我使用 PyCharm (Python3)来编写一个 Python 函数,该函数接受字典作为 attachment={}
的参数。
def put_object(self, parent_object, connection_name, **data):
...
def put_wall_post(self, message, attachment={}, profile_id="me"):
return self.put_object(profile_id, "feed", message=message, **attachment)
在 IDE 中,attachment={}
是黄色的。将鼠标移动到它上面会显示一个警告。
默认参数值是可变的
此检查检测列表或字典中的可变值何时为 在参数的默认值中检测到。
默认参数值在函数定义时只计算一次 时间,这意味着修改参数的默认值 将影响函数的所有后续调用。
这意味着什么? 我该如何解决这个问题?