Polymorphism in Python

前端 未结 2 1466
旧时难觅i
旧时难觅i 2021-01-20 20:28
class File(object):
    def __init__(self, filename):
        if os.path.isfile(filename):
            self.filename = filename
            self.file = open(filename         


        
2条回答
  •  旧时难觅i
    2021-01-20 21:01

    Prefixing an attribute with double underscores doesn't make the attribute private, it simply makes polymorphism impossible because the attribute name gets mangled with the current class name. Change it to a single underscore prefix instead.

提交回复
热议问题