当第一项持有一对可变对时,可变rlist(作业)

时间:2015-01-01 12:56:46

标签: python python-3.x

def mutable_pair(x,y):
    def get_item(index):
        if index == 0:
            return x
        return y
    def set_item(index , val):
        nonlocal x,y
        if  index == 0:
            x = val
        else:    
            y = val    

def make_dict():    
    contents = None
    def make_rlist(first,rest):
        return (first,rest)

    def dispatch(message,key,value):
        nonlocal contents
        if message == 'push_first':
            contents = make_rlist(mutable_pair(key, value), contents)
z = make_dict()
z('push_first')(2,4)

我有这个问题,当我试图运行此代码时,我得到下一个错误:

Traceback (most recent call last):
File "C:\Users\Michael\workspace\HomeWork1\src\tests.py", line 35, in <module>
z('push_first')(2,4)
TypeError: 'NoneType' object is not callable:

对我错误的地方有所帮助

1 个答案:

答案 0 :(得分:1)

  

TypeError:'NoneType'对象不可调用:

make_dict会返回None,因此zNonez('push_first')将无效。