How can I call super() so it's compatible in 2 and 3?

☆樱花仙子☆ 提交于 2019-12-10 12:32:16

问题


I'm trying to write 2/3 compatible code using six, but I don't see how I can call super() in a cross-compatible manner. Is there some better way besides, for example:

class MyClass(MyBase):
    def __init__():
        if six.PY3:
            super().__init__()
        else:
            super(MyClass, self).__init__()
        ...

回答1:


Using super() with arguments is backwards compatible, so you should just be able to use super(MyClass, self) without needing to check the version.



来源:https://stackoverflow.com/questions/21768391/how-can-i-call-super-so-its-compatible-in-2-and-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!