python - 如何去特定的线路再次检查条件?
问题描述
if net.res_bus.vm_pu[self.bus] > 1.005 :
self.p_mw = self.p_mw + self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)
self.soc_percent += ((self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)*15/60)/self.max_e_mwh) * 100
我在 Python 中使用 pandapower 包。在这里,我需要检查一个条件,如果它是真的,我需要执行一些计算,在完成计算后我需要再次检查它,这应该一直持续到它是真的。所以,这里我需要在计算后再次进入 if 条件。我怎样才能做到这一点?我试过for循环,它在某个地方搞砸了。
解决方案
您正在寻找一个 pythonwhile
循环。
您可以像这样构造您的代码,将 替换if
为while
:
while net.res_bus.vm_pu[self.bus] > 1.005 :
self.p_mw = self.p_mw + self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)
self.soc_percent += ((self.data_source.get_time_step_value(time_step=time,profile_name=self.p_profile)*15/60)/self.max_e_mwh) * 100
如果没有更好地理解您的代码,我看不到任何地方的值发生了net.res_bus.vm_pu[self.bus]
变化。如果是这种情况,您可能需要检查while
推荐阅读
- php - Phpstorm Composer 类重命名
- python - 在任务调度程序中自动化我的 python 脚本之后。从 URL 链接获取数据时出错
- python - 出现此错误的未知原因
- angular - Angular + Bootstrap(网格)+ 组件
- reactjs - 刷新时反应路由器黑屏
- kotlin - 如何检查类属性是否是 Kotlin 中的 List 类型
- javascript - 即使刷新页面,如何使我的购物车项目仍然存在?
- android - 使用 Firebase 远程配置将用户列入功能标志白名单的最佳方式?
- vue.js - 在 Vuetify 数据表中,如何访问选定的排序参数?
- reactjs - react-testing-library 的 fireEvent.click 在测试 react-native-web 时未更新 debug() 的结果