为什么我会得到语法:' yart'外部功能?
我正在尝试使用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:'farter'外部功能]
我是Python的新手,所以我感谢您的帮助,非常感谢!
I am trying to use PyCharm to read a locked excel file and I used the following code:
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
Can anyone tell me what's wrong with this yield function? I have been getting
[SyntaxError: 'yield' outside function]
I am new to python so I would appreciate some help, thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
收益率是只能在函数中使用的关键字,您将其称为外部任何函数,因此无法正常工作
https://www.geeksforgeeks.org/python-yield-keyword/
您可以在这里或在官方文档中阅读更多有关它的信息
https:///docs.pypython.org/3/reference/ simple_stmts.html#YEILD-Statement
Yield is a keyword that can only be used in a function, you called it outside any function so that won't work
https://www.geeksforgeeks.org/python-yield-keyword/
You could read more about it here or in the official documentations
https://docs.python.org/3/reference/simple_stmts.html#the-yield-statement
错误“ SyntaxError:'屈服'外部功能”本身说“收益”关键字用于外部函数。
一个简单的示例如何使用产量如下:
DEF CONCOL_FACTOR(n):
x = common_factors(100)
print(x)#prints< generator object object common_factors at 0x0000023efbbe1e70>
打印(列表(x))#打印[1、2、4、5、10、20、25、50、100]
The error "SyntaxError: 'yield' outside function" itself says the "yield" keyword is used outside function.
One simple example how to use yield is shown below:
def common_factors(n):
x = common_factors(100)
print(x) # prints <generator object common_factors at 0x0000023EFBBE1E70>
print(list(x)) # prints [1, 2, 4, 5, 10, 20, 25, 50, 100]