如何避免通过python中的if语句多次重复条件?

阿米奥林

有没有更好的方法来避免 if 语句多次重复条件?

 for entity in entities:
        if (entity.entity_id.startswith('sensor') and  "sourcenodeid" not in entity.entity_id and "interval" not in entity.entity_id and "previous"  not in entity.entity_id and "exporting" not in entity.entity_id and "management" not in entity.entity_id and "yr" not in entity.entity_id and "alarm" not in entity.entity_id ):
            data = remote.get_state(api, entity.entity_id)
            #print(data)

我试过了,or但它不能正常工作,因为我得到了不应该存储在数据中的条件的实体。

丹尼尔罗斯曼

使用带有all.

if entity.entity_id.startswith('sensor') and all(elem not in entity.entity_id for elem in ("sourcenodeid", "interval", "previous", "exporting", "management", "yr", "alarm")):

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何避免通过Winform在表中输入重复值?

来自分类Dev

如何改善Python中try语句的重复使用?

来自分类Dev

如何避免多次重复数据库查询

来自分类Dev

如何重构“使用”语句以避免代码重复?

来自分类Dev

python中的“ If not”条件语句

来自分类Dev

如何减少Python中If-Else语句的代码重复

来自分类Dev

避免在nodejs模块中重复require语句

来自分类Dev

如何避免用PHP SQL预准备语句重复代码?

来自分类Dev

通过ID连接时如何避免在字段层次结构中重复行值

来自分类Dev

如何避免重复的switch语句

来自分类Dev

如何避免通过python中的for循环覆盖值?

来自分类Dev

如何通过Vue.js避免不同功能中的重复代码?

来自分类Dev

避免在子查询中重复WHERE条件

来自分类Dev

避免在Python中多次打开/关闭文件

来自分类Dev

如何简化模板中的条件以避免重复

来自分类Dev

如何通过流插入避免在BigQuery中重复

来自分类Dev

避免在python中重复回答

来自分类Dev

如何避免在我的Python Spider程序中重复下载网址?

来自分类Dev

python中的条件语句

来自分类Dev

如何通过使用linq避免下拉列表中的重复项?

来自分类Dev

AngularJS Ui-grid DataTables,如何避免多次重复

来自分类Dev

如何通过Python删除在列表中多次出现的项目?

来自分类Dev

工厂中重复的条件语句

来自分类Dev

如何避免在python包中重复命名?

来自分类Dev

如何避免在没有通过引用的情况下在Python中重复工作?

来自分类Dev

如何通过在模型方法中使用 ValueError 避免模型管理器中的重复

来自分类Dev

避免python中的if else条件

来自分类Dev

如何避免在此 LINQ 中重复部分语句

来自分类Dev

在循环中多次重复每个语句 Python

Related 相关文章

热门标签

归档