Python-内部类未定义? [英] Python - inner class is not defined?

查看:90
本文介绍了Python-内部类未定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为我的一个课程做一个展开的链表.我是python的新手,但不是编程的新手,由于某种原因,我无法解决这个小问题!

I have to do an unrolled linked list for one of my classes. I'm new to python, but not to programming, and for some reason I cannot get around this little problem!

我有一个Node类,它将成为展开的链表中使用的节点对象.展开的链表类对Node类执行所有操作.

I have a class Node that is to be the node object used within the unrolled linked list. The unrolled linked list class performs all the operations on the Node class.

class UnrolledLinkedList(object):

    """ INNER NODE CLASS """
    class Node(object):
        def __init__(self):
            self.array = []
            self.next_node = None
    """ END NODE CLASS """

    def __init__(self, max_node_capacity=16):
        self.max_node_capacity = max_node_capacity
        self.head = Node()


    """ OTHER FUNCTIONS OF UNROLLEDLINKEDLIST CLASS """

问题出在UnrolledLinkedList类的 init 函数的最后一行:未定义全局名称Node".我仔细检查了缩进量,并在整个Internet上查找了类似示例,但找不到任何示例.有人介意向我解释怎么了吗?

The problem comes at the last line of the UnrolledLinkedList class' init function: "global name Node is not defined". I double checked my indentation and looked all over the internet for examples of something like this, but couldn't find any. Would someone mind explaining to me what's wrong?

推荐答案

方法包括其类作为要搜索的范围.如果您希望此方法有效,那么您将需要使用UnrolledLinkedList.Nodeself.Node代替.

Methods do not include their class as a scope to be searched. If you want this to work then you will need to use either UnrolledLinkedList.Node or self.Node instead.

这篇关于Python-内部类未定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆