擅长:python、mysql、java
<p><a href="https://stackoverflow.com/questions/58458664/increment-schedule-modules-day-attribute-with-variable-in-python/58458718#58458718">In another question I posted</a>,我最初试图用字符串替换day属性,就像Vig在这篇文章的回答中所建议的那样。这对我不起作用,所以我最终将对象存储在一个数组中,正如Prune在我最初的问题中所建议的那样。你知道吗</p>
<p>然而,Prune还将<a href="https://www.programcreek.com/python/example/82317/schedule.every" rel="nofollow noreferrer">a link</a>发布到了一个示例(示例7),在该示例中,整个调度时间的调用都存储在一个字符串中,然后通过<code>eval()</code>调用,这似乎是可行的。你知道吗</p>
<p>所以这就是我最后要做的:</p>
<pre><code>dayArray = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
dayTimeArray = []
for i in range(1, xlsxAlarmSheet.ncols):
for j in range(1, 8):
if(str(xlsxAlarmSheet.cell_value(j, i)) != '0'):
dayTimeArray.append(
"schedule.every().{}.at('{}').do(StartSubProcess)".format(
dayArray[j - 1],
str(xlsxAlarmSheet.cell_value(j, i))[:2] + ':' + str(xlsxAlarmSheet.cell_value(j ,i))[2:]
)
)
for i in range(0, len(dayTimeArray)):
eval(dayTimeArray[i])
</code></pre>