【问题标题】:python dict not getting updated code block in for loop getting triggred again and againpython dict在for循环中没有得到更新的代码块一次又一次地被触发
【发布时间】:2023-03-14 18:35:02
【问题描述】:

下面的代码块在 for 循环内,如果此特定条件满足但 dict 未更新并且当 print(context.memory_df[sec_name + "_buy_trade_entry"]) 它显示 True 尝试了很多可能有一些语法错误无法弄清楚

elif (context.current_time.time() >= datetime.time(context.memory_df["time_stop"][0],context.memory_df["time_stop"][1])) and (context.memory_df[sec_name + "_buy_trade_entry"] == True):
        print("16")
        context.memory_df[sec_name + "_buy_trade_entry"] == "time_exit"

        trade = [context.current_time,sec_name,context.memory_df[sec_name + "_atm_strike"],"BUY",
                            ce_price,pe_price,"exit",ce_wing_price,pe_wing_price,
                            context.memory_df[sec_name + "_what_to_buy"]]

        print(context.memory_df[sec_name + "_buy_trade_entry"]) # getting True instead of "time_exit"
        lv.save(context.memory_df_path,context.memory_df)
        lv.record_trade(trade,context.trade_rec_path)
        lv.record_trade(trade,context.every_day_trade_rec_path)
        order_placer(context,data,"long_exit_" + context.memory_df[sec_name + "_what_to_buy"],sec_name)
        winsound.Beep(2500, 2000)

【问题讨论】:

    标签: python


    【解决方案1】:

    从顶部的第三行 - 你有双等号 - 只需将其设为单一个:

    context.memory_df[sec_name + "_buy_trade_entry"] = "time_exit"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 2018-08-19
      • 2021-08-12
      相关资源
      最近更新 更多