<i id='nquvf'><tr id='nquvf'><dt id='nquvf'><q id='nquvf'><span id='nquvf'><b id='nquvf'><form id='nquvf'><ins id='nquvf'></ins><ul id='nquvf'></ul><sub id='nquvf'></sub></form><legend id='nquvf'></legend><bdo id='nquvf'><pre id='nquvf'><center id='nquvf'></center></pre></bdo></b><th id='nquvf'></th></span></q></dt></tr></i><div id='nquvf'><tfoot id='nquvf'></tfoot><dl id='nquvf'><fieldset id='nquvf'></fieldset></dl></div>
  • <tfoot id='nquvf'></tfoot>

      <small id='nquvf'></small><noframes id='nquvf'>

      • <bdo id='nquvf'></bdo><ul id='nquvf'></ul>
    1. <legend id='nquvf'><style id='nquvf'><dir id='nquvf'><q id='nquvf'></q></dir></style></legend>
      1. 为什么我不能在 Python 中扩展 bool?

        Why I can#39;t extend bool in Python?(为什么我不能在 Python 中扩展 bool?)
        <tfoot id='eGfex'></tfoot>

                  <tbody id='eGfex'></tbody>
              1. <legend id='eGfex'><style id='eGfex'><dir id='eGfex'><q id='eGfex'></q></dir></style></legend>
                  <bdo id='eGfex'></bdo><ul id='eGfex'></ul>
                  <i id='eGfex'><tr id='eGfex'><dt id='eGfex'><q id='eGfex'><span id='eGfex'><b id='eGfex'><form id='eGfex'><ins id='eGfex'></ins><ul id='eGfex'></ul><sub id='eGfex'></sub></form><legend id='eGfex'></legend><bdo id='eGfex'><pre id='eGfex'><center id='eGfex'></center></pre></bdo></b><th id='eGfex'></th></span></q></dt></tr></i><div id='eGfex'><tfoot id='eGfex'></tfoot><dl id='eGfex'><fieldset id='eGfex'></fieldset></dl></div>

                  <small id='eGfex'></small><noframes id='eGfex'>

                • 本文介绍了为什么我不能在 Python 中扩展 bool?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  >>> class BOOL(bool):
                  ...     print "why?"
                  ... 
                  why?
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  TypeError: Error when calling the metaclass bases
                      type 'bool' is not an acceptable base type
                  

                  我认为 Python 信任程序员.

                  推荐答案

                  Guido 的看法:

                  我最后想到了这个晚上,并意识到你不应该完全可以继承 bool !一个子类只有在它有用时才有用有实例,但仅仅是存在bool 子类的实例会打破 True 的不变量和 False 是唯一的实例布尔!(C 的子类的一个实例也是 C 的一个实例.)我认为重要的是不要提供后门创建额外的布尔实例,所以我认为 bool 不应该可以子类化.

                  I thought about this last night, and realized that you shouldn't be allowed to subclass bool at all! A subclass would only be useful when it has instances, but the mere existance of an instance of a subclass of bool would break the invariant that True and False are the only instances of bool! (An instance of a subclass of C is also an instance of C.) I think it's important not to provide a backdoor to create additional bool instances, so I think bool should not be subclassable.

                  参考:http://mail.python.org/pipermail/python-dev/2002-March/020822.html

                  这篇关于为什么我不能在 Python 中扩展 bool?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)

                        • <bdo id='5IjAE'></bdo><ul id='5IjAE'></ul>

                            <small id='5IjAE'></small><noframes id='5IjAE'>

                            <legend id='5IjAE'><style id='5IjAE'><dir id='5IjAE'><q id='5IjAE'></q></dir></style></legend>
                              <tbody id='5IjAE'></tbody>
                            <tfoot id='5IjAE'></tfoot>
                            <i id='5IjAE'><tr id='5IjAE'><dt id='5IjAE'><q id='5IjAE'><span id='5IjAE'><b id='5IjAE'><form id='5IjAE'><ins id='5IjAE'></ins><ul id='5IjAE'></ul><sub id='5IjAE'></sub></form><legend id='5IjAE'></legend><bdo id='5IjAE'><pre id='5IjAE'><center id='5IjAE'></center></pre></bdo></b><th id='5IjAE'></th></span></q></dt></tr></i><div id='5IjAE'><tfoot id='5IjAE'></tfoot><dl id='5IjAE'><fieldset id='5IjAE'></fieldset></dl></div>