简体   繁体   English

尝试从pygame.midi继承时出错

[英]Error trying to inherit from pygame.midi

I am working on a program, and I want to have a class that inherits everything from pygame.midi. 我正在开发一个程序,并且想拥有一个从pygame.midi继承所有内容的类。 However, when I attempt to do this, I get this error: 但是,当我尝试执行此操作时,出现以下错误:

Traceback (most recent call last):
  File "/Users/KelsenHazelwood/Documents/School/CS 23000/qBasicMusicMaker.py", line 5, in 
    class userSong (midi):
TypeError: module.__init__() takes at most 2 arguments (3 given)

Here is the code I've been working with: 这是我一直在使用的代码:

from pygame import midi

class userSong (midi):
    def __init__ (self):
        pass
        #super (midi,self).__init__()

def main():
    k = userSong ()

main ()

pygame.midi is a module . pygame.midi是一个模块 You can't inherit from a module, only classes. 您不能从模块继承,只能从类继承。 You could import every class in pygame.midi , and inherit from one of them. 您可以在pygame.midi导入每个类,并从one继承。 Technically, it would be possible to inherit from all of them , but that's a terrible idea - the functionality is split into various classes for a reason. 从技术上讲,可以从all of them继承,但这是一个糟糕的主意-出于某种原因将功能划分为多个类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM