AttributeError: type object 'Student' has no attribute 'cm'
时间: 2023-10-01 16:09:30 浏览: 113
这个错误通常是因为Python对象缺少某个属性而导致的。在你提供的引用中,错误信息显示"type object 'Student' has no attribute 'cm'"。这意味着在某个名为"Student"的对象中没有名为"cm"的属性。
要解决这个错误,可以检查以下几点:
1. 确保在定义Student类时,确实添加了名为"cm"的属性。
2. 确保在创建Student对象之后,没有意外地修改或删除了"cm"属性。
3. 检查是否在访问"cm"属性之前,已正确实例化了Student类的对象。
可以根据下面的代码示例检查你的实现:
```python
class Student:
def __init__(self, name, cm):
self.name = name
self.cm = cm
student = Student("John", 180)
print(student.cm)
```
请注意,以上是一种可能的解决方法,具体解决方法还取决于你的代码实现。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [关于AttributeError: type object ‘XXX‘ has no attribute ‘XXX‘的问题](https://blog.csdn.net/YZL40514131/article/details/120838681)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [出现AttributeError: type object ‘object‘ has no attribute ‘dtype‘的另一种问题](https://blog.csdn.net/HopeorWish/article/details/121222984)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文