N—E—E
2021-07-18 13:59
采纳率: 61.1%
浏览 95
已结题

python “module' object is not callable”报错


import operator
import BinaryTree
from stackpractise import stack

def buildparsetree(fpexp):
    tree=BinaryTree('')
    s=stack()
    current=tree
    for i in fpexp:
        if i == '(':
            s.push(current)
            current.insertleft('')
            current=current.getleftchild()
        elif i not in '+-*/)':
            current.setrootval(int(i))
            current=s.pop()
        elif i in '+-*/':
            current.setrootval(i)
            current.insertright('')
            s.push(current)
            current=current.getrightchild()
        elif i == ')':
            current=s.pop()
        else:
            return False
    return tree


def evluate(parsetree):
    opers={'+':operator.add,'-':operator.sub,'*':operator.mul,'/':operator.truediv()}
    leftc=parsetree.getleftchild()
    rightc=parsetree.getrightchild()
    if leftc and rightc:
        fn=opers[parsetree.getrootval()]
        return fn(evluate(leftc),evluate(rightc))
    else:
        return parsetree.getrootval()

t=buildparsetree('(1+(2+3)')
print(evluate(t))

Traceback (most recent call last):
  File "D:\pythonwork\Tree\构建解析树.py", line 39, in <module>
    t=buildparsetree('(1+(2+3)')
  File "D:\pythonwork\Tree\构建解析树.py", line 6, in buildparsetree
    tree=BinaryTree('')
TypeError: 'module' object is not callable

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • weixin_45864635 2021-07-18 15:04

    tree=BinaryTree('')
    current=tree

    这2个是不是应该改成
    current = BinaryTree.tree()

    评论
    解决 1 无用
    打赏 举报

相关推荐 更多相似问题