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

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()

    评论

报告相同问题?

问题事件

  • 系统已结题 7月25日
  • 创建了问题 7月18日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog