python-3.x - 解析命名空间 xml 生成 AttributeError: 'str' object has no attribute 'text'
问题描述
以下代码导致此错误“AttributeError:'str'对象没有属性'text'”可以告诉我如何解决这个错误。此错误是由 value.text = str(ImageState) 引起的
for ecu_container in root.findall('.//{http://autosar.org/schema/r4.0}ECUC-CONTAINER-VALUE'):
short_name = ecu_container.find('.//{http://autosar.org/schema/r4.0}SHORT-NAME').text
if(short_name == component):
value = ecu_container.find('.//{http://autosar.org/schema/r4.0}VALUE').text
value.text = str(imageState)
解决方案
我发现了我的问题。命令
值 = ecu_container.find('.//{http://autosar.org/schema/r4.0}VALUE').text 不正确。它应该是
value = ecu_container.find('.//{http://autosar.org/schema/r4.0}VALUE')。
我已将 .text 添加到此行以读取数据,以确保获得正确的数据以进行更新,但在尝试写入数据时从未删除 .text。
推荐阅读
- python-3.x - 命令 np.empty 是否有可能生成一个非常大的数字而不是一个非常小的数字?
- scala - 在 Spark 中垂直拆分和附加同一列时排序
- javascript - 如何使用过滤器为数组中的特定对象动态分配 ng-model?
- python-3.x - 使用 Batch .bat 安排 Python Selenium 每天运行
- angular - 使用本地主机配置 angular rest url
- python - Python 抛出列表索引超出范围错误
- r - 为什么在因子上使用 as.numeric() 时没有警告?
- amazon-web-services - 如何删除目标组中的最后一条规则
- python - 类型错误:列表索引必须是整数或切片,而不是 str 尝试使用 cx_Freeze 将 .py 文件转换为 .exe 时
- python - Keras:使用 flow_from _directory() 函数为两个输入模型创建自定义生成器