Can I use Python 3 super() in Python 2.5.6?

前端 未结 4 1727
自闭症患者
自闭症患者 2021-01-07 23:10

Can I use clean Python 3 super() syntax in Python 2.5.6?
Maybe with some kind of __future__ import?

4条回答
  •  臣服心动
    2021-01-07 23:38

    You cannot use a bare super() call that contains no type/class. Nor can you implement a replacement for it that will work. Python 3.x contains special support to enable bare super() calls (it places a __class__ cell variable in all functions defined within a class - see PEP 3135


    Update

    As of Python 2.6+, bare super() calls can be used via the future Python package. See posita's answer for an explanation.

提交回复
热议问题