擅长:python、mysql、java
<p>这看起来很奇怪(它是从哪里来的?)在</p>
<pre><code>if self.__dict__ in (name):
</code></pre>
<p>不是吗</p>
^{pr2}$
<p>这修正了你的例子</p>
<pre><code>Python 3.2.3 (default, May 3 2012, 15:51:42)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import const
>>> const.magic = 23
>>> const.magic = 88
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "const.py", line 6, in __setattr__
raise self.ConstError("Can't rebind const(%s)"%name)
const.ConstError: Can't rebind const(magic)
</code></pre>
<p>你真的需要这个警员黑客吗?很多Python代码似乎在某种程度上没有它也能工作</p>