为什么 sched 会破坏我的琴弦
Why is sched breaking apart my strings
我正在尝试将 sched 用于 运行 tweetsearch,该函数接受一个参数,一个字符串。
s.enter(delaypercycle, 1, tweetsearch, "nike")
s.run()
这个returns"TypeError: tweetsearch() takes exactly 1 argument (4 given)"。
将 "nike" 更改为 "chicken" returns 同样的错误,除了 (7 given).
知道如何将字符串传递给 sched 吗?
产生相同错误的示例代码:
import sched, time
s = sched.scheduler(time.time, time.sleep)
def printword(word):
print word
While True:
s.enter(1, 1, printword, "chicken")
s.run
它需要一个 元组 个参数。传入一个字符串会导致它将该字符串用作可迭代对象:每个字符都成为一个单独的参数。
尝试传递一个元组:("Nike",)
(注意尾随逗号)。
将您的代码更改为:
s.enter(delaypercycle, 1, tweetsearch, ("nike",))
s.run()
sched
试图做 tweetsearch(*"nike")
,这等同于 tweetsearch('n', 'i', 'k', 'e')
.
我正在尝试将 sched 用于 运行 tweetsearch,该函数接受一个参数,一个字符串。
s.enter(delaypercycle, 1, tweetsearch, "nike")
s.run()
这个returns"TypeError: tweetsearch() takes exactly 1 argument (4 given)"。 将 "nike" 更改为 "chicken" returns 同样的错误,除了 (7 given).
知道如何将字符串传递给 sched 吗?
产生相同错误的示例代码:
import sched, time
s = sched.scheduler(time.time, time.sleep)
def printword(word):
print word
While True:
s.enter(1, 1, printword, "chicken")
s.run
它需要一个 元组 个参数。传入一个字符串会导致它将该字符串用作可迭代对象:每个字符都成为一个单独的参数。
尝试传递一个元组:("Nike",)
(注意尾随逗号)。
将您的代码更改为:
s.enter(delaypercycle, 1, tweetsearch, ("nike",))
s.run()
sched
试图做 tweetsearch(*"nike")
,这等同于 tweetsearch('n', 'i', 'k', 'e')
.