小编use*_*182的帖子

在Python 2.7中使用repr和super.`super().__ repr__` vs`repr(super())`

问题:为什么repr(super(class, thing))不同super(class, thing).__repr__()

我遇到过一些我认为很奇怪的事情,如果有人解释为什么它的工作方式会很好,那就太棒了.

我的问题是如何repr运作

class MyInt(int):
    pass

one = MyInt(1)
sup = super(MyInt, one)
Run Code Online (Sandbox Code Playgroud)

>>> repr(sup)

"<super: <class 'MyInt'>, <MyInt object>>"

>>> sup.__repr__()

'1'

第二个是我期望从第一个开始的(是的,引用在每种情况下都不同).为什么这些案件有所repr不同?我以为repr(x)刚刚打过电话x.__repr__.


据我所知,super为超类的方法提供了一个API,而不是超类本身.所以在我看来,我sup有两个__repr__方法,一个由名称调用repr,一个名称在名称之下__repr__.非常感谢能够深入了解这里发生的事情.

python internals repr super python-2.7

6
推荐指数
0
解决办法
217
查看次数

如何让fprintf显示更高的精度?

我正在尝试使用以下 fprintf 代码

      n
      m
     fprintf('The minimum value of the modulus of the image of C_r is %d \n\nThe correspoding point is at %d \n\n',m,n)
Run Code Online (Sandbox Code Playgroud)

我得到了结果

  n =

  3.632213809443102 + 3.680287679864827i


m =

   5.170831128945713

The minimum value of the modulus of the image of C_r is 5.170831e+000 

The correspoding point is at        3.632214e+000 
Run Code Online (Sandbox Code Playgroud)

我分别打印了 n 和 m 的值,以显示我希望它们如何显示 - 如何让 fprintf 以更高的精度显示数字?我尝试更改 %d 条款但无济于事

matlab printf

1
推荐指数
1
解决办法
7621
查看次数

标签 统计

internals ×1

matlab ×1

printf ×1

python ×1

python-2.7 ×1

repr ×1

super ×1