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

Nick T

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__()
        ...
Andrew Clark

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

How can i get the value of a variable through the Super keyword?

来自分类Dev

How can I use SQL's YEAR(), MONTH() and DAY() in Doctrine2?

来自分类Dev

How to parse a text file (CSV) into haskell so I can operate on it?

来自分类Dev

Super + 1,Super + 2,Super + 3等键无法在Gnome中重新映射

来自分类Dev

How to call a controller from JS so the controller can perform its request mappings?

来自分类Dev

How do I access variadic template parameters in a way that is constexpr compatible?

来自分类Dev

How can I get 3D object dimensions in ThreeJS?

来自分类Dev

How can I enable/disable a UITextField's inputAccessoryView buttons?

来自分类Dev

How can I find who pushed a tag(s) to BitBucket

来自分类Dev

how can i prevent nested list's click event

来自分类Dev

How can I find the string value of a property given it's value

来自分类Dev

如何调用super()使其在2和3中兼容?

来自分类Dev

How am I using copytree wrong and how can I fix it so it doesn't get caught in a huge loop?

来自分类Dev

How can I preserve the value of my parameters through a function so it can be used multiple times with its initial value?

来自分类Dev

Openshift 3 - 覆盖 .s2i/bin 文件 - 组装和运行脚本

来自分类Dev

如何使用C#将文件上传到Amazon S3 super easy

来自分类Dev

How do I call an intent in Retrofit Callback?

来自分类Dev

In Python 3 how can I patch a function inside a module for unit testing?

来自分类Dev

How Can I implement policyId and enable Monetization YouTube v3 with .NET

来自分类Dev

How can I minify html, css, js/jquery and ruby code inside Sublime Text 3?

来自分类Dev

Why can't I call toString() on a double value?

来自分类Dev

Can I use Mockito to insert a delay and then call the real method?

来自分类Dev

How can I add a customized buttons to the AlloyUI Scheduler's event popup?

来自分类Dev

C++ Shared pointers. How can I change the underlying object's pointer for all copies?

来自分类Dev

How can I see a Web API bearer token before it's returned?

来自分类Dev

How can I make Javascript's reduce method work on arrays of arrays?

来自分类Dev

python super :TypeError: __init__() 需要 2 个位置参数,但给出了 3 个

来自分类Dev

Python Multiple Inheritance: call super on all

来自分类Dev

How can I cancel an ngEvent?

Related 相关文章

  1. 1

    How can i get the value of a variable through the Super keyword?

  2. 2

    How can I use SQL's YEAR(), MONTH() and DAY() in Doctrine2?

  3. 3

    How to parse a text file (CSV) into haskell so I can operate on it?

  4. 4

    Super + 1,Super + 2,Super + 3等键无法在Gnome中重新映射

  5. 5

    How to call a controller from JS so the controller can perform its request mappings?

  6. 6

    How do I access variadic template parameters in a way that is constexpr compatible?

  7. 7

    How can I get 3D object dimensions in ThreeJS?

  8. 8

    How can I enable/disable a UITextField's inputAccessoryView buttons?

  9. 9

    How can I find who pushed a tag(s) to BitBucket

  10. 10

    how can i prevent nested list's click event

  11. 11

    How can I find the string value of a property given it's value

  12. 12

    如何调用super()使其在2和3中兼容?

  13. 13

    How am I using copytree wrong and how can I fix it so it doesn't get caught in a huge loop?

  14. 14

    How can I preserve the value of my parameters through a function so it can be used multiple times with its initial value?

  15. 15

    Openshift 3 - 覆盖 .s2i/bin 文件 - 组装和运行脚本

  16. 16

    如何使用C#将文件上传到Amazon S3 super easy

  17. 17

    How do I call an intent in Retrofit Callback?

  18. 18

    In Python 3 how can I patch a function inside a module for unit testing?

  19. 19

    How Can I implement policyId and enable Monetization YouTube v3 with .NET

  20. 20

    How can I minify html, css, js/jquery and ruby code inside Sublime Text 3?

  21. 21

    Why can't I call toString() on a double value?

  22. 22

    Can I use Mockito to insert a delay and then call the real method?

  23. 23

    How can I add a customized buttons to the AlloyUI Scheduler's event popup?

  24. 24

    C++ Shared pointers. How can I change the underlying object's pointer for all copies?

  25. 25

    How can I see a Web API bearer token before it's returned?

  26. 26

    How can I make Javascript's reduce method work on arrays of arrays?

  27. 27

    python super :TypeError: __init__() 需要 2 个位置参数,但给出了 3 个

  28. 28

    Python Multiple Inheritance: call super on all

  29. 29

    How can I cancel an ngEvent?

热门标签

归档