提问人:Shawn Alcantara 提问时间:6/17/2022 最后编辑:jpsShawn Alcantara 更新时间:6/17/2022 访问量:213
为什么我收到 SyntaxError: 'yield' outside function?
why I am getting SyntaxError: 'yield' outside function?
问:
我正在尝试使用 PyCharm 读取锁定的 excel 文件,我使用了以下代码:
with open('abcd.xlsm', 'rb') as abcd1:
excel = msoffcrypto.OfficeFile('abcd.xlsm')
excel.load_key('1234')
excel.decrypt(temp)
abcd1.seek(0, os.SEEK_END)
while True:
lines = abcd1.readline()
if not lines:
time.sleep(0.1)
continue
yield lines
谁能告诉我这个屈服函数有什么问题?我一直在得到
[SyntaxError: 'yield' 外部函数]
我是python的新手,所以我希望得到一些帮助,非常感谢!
答:
1赞
Eldar Shua
6/17/2022
#1
Yield 是一个只能在函数中使用的关键字,您在任何函数之外调用它,因此它不起作用
https://www.geeksforgeeks.org/python-yield-keyword/您可以在此处或在官方文档中阅读有关它的更多信息 https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement
评论