Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 进口商品包括什么_Python_Import - Fatal编程技术网

Python 进口商品包括什么

Python 进口商品包括什么,python,import,Python,Import,我是python新手,所以如果我想问一些简单的问题,请原谅。我正在试验导入功能。我想知道如果导入一个模块,我可以从该模块中创建类吗。以下是我的模块代码: class Parent(object): def override(self): print("PARENT override") def implicit(self): print("PARENT implicit") def altered(self): pri

我是python新手,所以如果我想问一些简单的问题,请原谅。我正在试验导入功能。我想知道如果导入一个模块,我可以从该模块中创建类吗。以下是我的模块代码:

class Parent(object):

    def override(self):
        print("PARENT override")

    def implicit(self):
        print("PARENT implicit")

    def altered(self):
        print("PARENT altered")


class Child(Parent):
    def override(self):
        print("CHILD override")


    def altered(self):
        print("CHILD, BEFORE PARENT altered")
        super(Child, self).altered()
        print("CHILD, PARENT altered")
下面是我要导入模块的脚本代码:

import test

dad = Parent()
print(dad)
我不断获取:name错误:未定义名称“Parent”


再一次,如果我完全弄错了,请原谅,为什么我不能从我刚导入的模块创建一个类呢?

使用
import test
,脚本中只提供名称
test
,您可以将
Parent
称为
test.Parent


如果您只想通过类的名称
Parent
,引用您的类,您应该使用test import Parent中的
,这样我就只能使用test中的独立函数了?@EliBaum:您可以使用所有功能,您只需将其称为
test.Parent
,而不是
Parent
,就像答案已经说的那样。@EliBaum我不确定你所说的“独立函数”是什么意思。这个问题有很好的解释。