How to extend a class in python?

前端 未结 2 477
独厮守ぢ
独厮守ぢ 2020-12-13 12:00

In python how can you extend a class? For example if I have

color.py

class Color:
    def __init__(self, color):
        self.color = color
    def g         


        
2条回答
  •  长情又很酷
    2020-12-13 12:35

    Use:

    import color
    
    class Color(color.Color):
        ...
    

    If this were Python 2.x, you would also want to derive color.Color from object, to make it a new-style class:

    class Color(object):
        ...
    

    This is not necessary in Python 3.x.

提交回复
热议问题