We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
测试代码:
from enum import Enum from objprint import op,add_objprint class temp_a(Enum): a = 1 @add_objprint class temp_b(Enum): b = 1 print("temp_a:\n",temp_a,"\n") print("temp_a.a:\n",temp_a.a,"\n") print("op_temp_a:") op(temp_a) print("\n") print("op_temp_a.a:") op(temp_a.a) print("\n") print("================================================================\n") print("temp_b:\n",temp_b,"\n") print("temp_b.b:\n",temp_b.b,"\n") print("op_temp_b:") op(temp_b) print("\n") print("op_temp_b.b:") op(temp_b.b) print("\n")
输出:
temp_a: <enum 'temp_a'> temp_a.a: temp_a.a op_temp_a: <enum 'temp_a'> op_temp_a.a: temp_a.a ================================================================ temp_b: <enum 'temp_b'> temp_b.b: <temp_b 0x24a740c2ee0 .__objclass__ = <enum 'temp_b'>, ._name_ = 'b', ._value_ = 1 > op_temp_b: <enum 'temp_b'> op_temp_b.b: <temp_b 0x24a740c2ee0 .__objclass__ = <enum 'temp_b'>, ._name_ = 'b', ._value_ = 1 >
符合直觉的结果应该是:
class temp_a(Enum): a = 1 op(temp_a)
<temp_a 0xFFFFFFFF .__objclass__ = <enum 'temp_a'>, .temp_a.a = < xxxxxxx ._name_ = 'b', ._value_ = 1 > >
The text was updated successfully, but these errors were encountered:
op(temp_a)是不可能输出temp_a的,因为temp_a是个class(type),而<temp_a ..>的形式打印的应该是个temp_aobject,这里明显不应该混淆。
temp_a
class
type
<temp_a ..>
@add_objprint也是一个道理,它改变的是object的输出,而不是class本身。
@add_objprint
就像下面的代码:
class A: def func(self): pass op(A) op(A())
你觉得打印的内容应该一样么……
还有,当你op一个自己定义了__str__的object的时候,op的默认behavior是尊重它的__str__,而class本身是个typeobject,type是有自己的__str__函数的。如果你想用op,你可以op(temp_a, honor_existing=False),就会看到一大串东西。
op
__str__
op(temp_a, honor_existing=False)
依然,它打印的是一个class,也就是type,而不是它的object。
Sorry, something went wrong.
好的 受教了
No branches or pull requests
测试代码:
输出:
符合直觉的结果应该是:
输出:
The text was updated successfully, but these errors were encountered: