我正在尝试制作一个简单的基于时间的脚本,用户在其中输入:
dt_call
time.perf_counter()
生成(又名float
)]是否有一个Python库的键值存储满足以下条件?
float
object
更多信息
这将是调度程序的一部分,调度程序经常在其中:
dt
if dT >= dt_call
当前最佳想法
目前,我最好的主意是基于此:Sort a list of tuples by 2nd item (integer value)
启动脚本之前:
dt_call
+对象对存储在tuple
中># Keys are `dt_call`
list_.sort(key=lambda x:x[0])
list_ # [(5.6, obj0), (5.9, obj1), (8.7, obj2)]
启动脚本后:
index
获取bisect.bisect
index - 1
处的对象。如果没有,请致电。# Start
start_time = time.perf_counter()
# Some time has passed
dt = time.perf_counter() - start_time
# Step 1
index = bisect.bisect([x[0] for x in list_], dt)
# Step 2
fetched_obj = list_[index - 1][1]
if fetched_obj.is_not_called():
fetched_obj()
是否可以使用一种数据结构以更直接的方式(全部合而为一)?
这个想法结合了多种数据结构来完成工作。
我正在尝试制作一个简单的基于时间的脚本,用户在其中输入:启动脚本以调用对象后的时间,该对象称为dt_call由time.perf_counter()(又称它是浮点数)生成的对象...
您提到的需要一个允许以下内容的数据结构: