AttributeError: can't set attribute
时间: 2023-11-07 17:37:06 浏览: 52
这个错误通常表示你在尝试给一个只读的属性赋值。在 Python 中,有些属性是只读的,不能被修改,因为它们是只能被访问而不能被更改的内部属性。如果你尝试给这些属性赋值,就会出现 "AttributeError: can't set attribute" 错误。
要解决这个问题,你需要检查你的代码,找到哪个属性是只读的,并且确保你没有尝试修改它。如果你需要修改这个属性,你需要找到一个可以修改它的方式,或者重新设计你的代码以避免修改它。
相关问题
SQLAlchemy修改数据时报错AttributeError: can t set attribute
这个错误通常是因为你在使用SQLAlchemy时尝试直接设置一个不可设置的属性。SQLAlchemy的模型类中的属性通常具有getter和setter方法,而不是直接访问属性。
要修改数据,你应该使用模型类对象的setter方法,而不是直接设置属性。例如,假设你有一个名为`User`的模型类,有一个名为`name`的属性,你应该使用`user.name = '新名称'`而不是`user.name = '新名称'`。
如果你已经使用了正确的setter方法,但仍然遇到此错误,请确保你的模型类中的属性定义正确,并且没有错误地覆盖了getter和setter方法。
如果你能提供更多的代码和错误信息,我可以给出更具体的帮助。
AttributeError: can't set attribute 'book'
引用\[1\]:AttributeError: can’t set attribute class A(B): def __init__(self,output_shape, **kwargs): self.output_shape = output_shape 。 引用\[2\]:报错代码如下: File "./ga_web/lib/meta_data.py", line 94, in instance_list_ip_port return \[x.get('ip')+':'+str(x.get('port')) for x in self.instance_list(filter)\] File "./ga_web/lib/meta_data.py", line 82, in instance_list for d in instance_list: File "/usr/local/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/db/models/query.py", line 1312, in __iter__ setattr(instance, column, values\[pos\]) AttributeError: can't set attribute 。 引用\[3\]:报错:AttributeError: can’t set attribute 原因:output_shape与你这个类继承的B中的某一参数重名(B也有output_shape这一参数),可以将output_shape改为outputShape。 问题:AttributeError: can't set attribute 'book'
回答: 这个错误是由于在设置属性时出现了问题。具体来说,'book'属性无法被设置。这可能是因为在代码中尝试设置一个不存在的属性,或者尝试设置一个只读属性。要解决这个问题,你需要检查代码中是否正确地定义了'book'属性,并确保它可以被设置。如果属性名与其他属性重名,你可以尝试将其改为不同的名称,以避免冲突。
#### 引用[.reference_title]
- *1* *3* [AttributeError: can‘t set attribute](https://blog.csdn.net/weixin_42316982/article/details/122639488)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [解决:AttributeError: can't set attribute](https://blog.csdn.net/dqchouyang/article/details/98973758)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)