首页 > 解决方案 > 使用 python 保存不同的预设

问题描述

对于我的浓缩咖啡机,我正在使用 PyQt5 在 Python 中编写 GUI。我想保存不同的“配置文件”,我可以根据我使用的 bean 来回忆它们。有一个用 TCL 编写的固件(来自名为“不错的浓缩咖啡机”的机器),它显示了我想要的内容(我将附上 2 张图像和其中一个描述文件的片段,该文件中的第 1 行包含不同的步骤)。

我不确定我应该使用哪个解析器。我显然总是想为相同的参数保存不同的值(在 c 中我会说相同的结构),所以在某种程度上使用像 configparser 这样总是有独立部分的东西感觉不对。

有人可以给我一个提示我应该使用什么库。总是有相同的参数,但不同的配方可能包含不同数量的步骤。

我想要这样的伪代码:

recipe=open('recipe1.txt')
currentstep=0
for steps in recipe:
    pressure = step[currentstep].pressure
    flow = step[currentstep].flow
    ...
    brew()
    currentstep = currentstep + 1

步骤 概述

这是在 TCL 文件中:

advanced_shot {{exit_if 1 flow 6.0 volume 100 transition fast exit_flow_under 0 temperature 90.0 name infuse pressure 1 sensor coffee pump flow exit_type pressure_over exit_flow_over 6 exit_pressure_over 3.0 exit_pressure_under 0 seconds 20.0} {exit_if 0 volume 100 transition fast exit_flow_under 0 temperature 90.0 name {rise and hold} pressure 9.0 sensor coffee pump pressure exit_flow_over 6 exit_pressure_over 11 seconds 10.0 exit_pressure_under 0} {exit_if 1 volume 100 transition smooth exit_flow_under 0 temperature 90.0 name decline pressure 4.0 sensor coffee pump pressure exit_type pressure_under exit_flow_over 1.2 exit_pressure_over 11 seconds 20.0 exit_pressure_under 4.0} {exit_if 1 flow 1.2 volume 100 transition smooth exit_flow_under 0 temperature 90.0 name {pressure limit} pressure 4.0 sensor coffee pump pressure exit_type flow_over exit_flow_over 1.0 exit_pressure_over 11 exit_pressure_under 0 seconds 10.0} {exit_if 0 flow 1.0 volume 100 transition smooth exit_flow_under 0 temperature 90.0 name {flow limit} pressure 3.0 sensor coffee pump flow exit_flow_over 6 exit_pressure_over 11 seconds 30.0 exit_pressure_under 0}}
author Decent
beverage_type espresso
espresso_decline_time 30
espresso_hold_time 15
espresso_pressure 6.0
espresso_temperature 90.0
final_desired_shot_volume 32
final_desired_shot_volume_advanced 0
final_desired_shot_weight 32
final_desired_shot_weight_advanced 36
flow_profile_decline 1.2
flow_profile_decline_time 17
flow_profile_hold 2
flow_profile_hold_time 8
flow_profile_minimum_pressure 4
flow_profile_preinfusion 4
flow_profile_preinfusion_time 5
preinfusion_flow_rate 4
preinfusion_guarantee 1
preinfusion_stop_pressure 4.0
preinfusion_time 20
pressure_end 4.0
profile_hide 0
profile_language en
profile_notes {An advanced spring lever profile by John Weiss that addresses a problem with simple spring lever profiles, by using both pressure and flow control. The last two steps keep pressure/flow under control as the puck erodes, if the shot has not finished by the end of step 3. Please consider this as a starting point for tweaking.}
profile_title {Advanced spring lever}
settings_profile_type settings_2c
tank_desired_water_temperature 0
water_temperature 80

标签: pythonparsing

解决方案


推荐阅读