如何解决AttributeError:“ str”对象没有属性“ eval”
我不断收到该错误:“ AttributeError:'str'对象没有属性'eval'”,有人可以告诉我如何解决它及其含义吗?这是我的代码顺便说一句:
from rply.token import BaseBox
class Loop(BaseBox):
def __init__(self,number,statementlist):
self.number = number
self.statementlist = statementlist
def eval(self):
for i in range(self.number):
self.statementlist.eval()
@staticmethod
def gettokentype():
return 'statement'
class While(BaseBox):
def __init__(self,condition,statementlist):
self.condition = condition
self.statementlist = statementlist
def eval(self):
while bool(self.condition.eval()):
self.statementlist.eval()
@staticmethod
def gettokentype():
return 'statement'
整个错误:
Traceback (most recent call last):
File "main.py",line 102,in <module>
parser.parse(tokens)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/rply/parser.py",line 49,in parse
current_state = self._reduce_production(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/rply/parser.py",line 80,in _reduce_production
value = p.func(targ)
File "/home/runner/RealMotionlessLivedistro/Core/parser.py",line 44,in program
return p[0].eval()
File "/home/runner/RealMotionlessLivedistro/Core/AST/Statements.py",line 27,in eval
i.eval()
File "/home/runner/RealMotionlessLivedistro/Core/AST/Loops.py",line 25,in eval
self.statementlist.eval()
File "/home/runner/RealMotionlessLivedistro/Core/AST/Statements.py",in eval
i.eval()
File "/home/runner/RealMotionlessLivedistro/Core/AST/Conditions.py",line 11,in eval
i.eval()
File "/home/runner/RealMotionlessLivedistro/Core/AST/Statements.py",line 9,in eval
self.exp.eval()
File "/home/runner/RealMotionlessLivedistro/Core/AST/Functions.py",line 55,in eval
self.value = self.value.eval()
AttributeError: 'str' object has no attribute 'eval'
我们非常感谢您的帮助,请xD
解决方法
如果您正在查看python内置函数eval()
,则其用法有所不同。
>>> x = 1
>>> eval('x+1')
2
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。