我知道这听起来像是一个疯狂的问题,但我想在发送到终端的命令中使用x变量,并且我没有其他的想法来使用它。我是python的新手。
def words(filepath):
with open(filepath,'r') as f:
for line in f:
for x in line.split():
## i tried adding yield x here and that didnt seem to work
## how the hell do i end this for loop
words = words('/users/zac/test.txt')
for x in words:
os.system('osascript send.scpt {} "{}"'.format('5555555555', x ))发布于 2020-07-31 18:06:27
你需要在这里使用yield来使它成为一个生成器。您可能希望遍历文件的各行,而不是字符。您需要使用:
for line in f.readlines():
for word in line.split():
yield wordhttps://stackoverflow.com/questions/63189710
复制相似问题