小编sth*_*ult的帖子

python2 vs python3函数到方法绑定

亲爱的python 3专家,

使用python2,可以执行以下操作(我知道这有点毛茸茸,但这不是重点:p):

class A(object):
  def method(self, other):
    print self, other

class B(object): pass

B.method = types.MethodType(A().method, None, B)
B.method() # print both A and B instances
Run Code Online (Sandbox Code Playgroud)

使用python3,没有更多的未绑定方法,只有函数.如果我想要相同的行为,听起来我要引入一个自定义描述符,例如:

class UnboundMethod:
    """unbound method wrapper necessary for python3 where we can't turn
    arbitrary object into a method (no more unbound method and only function
    are turned automatically to method when accessed through an instance)
    """
    def __init__(self, callable):
        self.callable = callable

    def __get__(self, instance, objtype):
        if instance is None:
            return self.callable
        return …
Run Code Online (Sandbox Code Playgroud)

python-2.x python-3.x

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

如何使用 react material-ui 编写媒体相关代码?

通过阅读文档,我认为后来的 material-ui 中的好解决方案是useMediaQuery,但充其量我无法正确解决。我的目标是在打印页面时隐藏菜单,所以我写了一些类似的东西:

if (!useMediaQuery("print")) {
  ... code to be hidden
}
Run Code Online (Sandbox Code Playgroud)

编译执行正常,但不起作用。当浏览器进入打印预览模式 (FF 65) 时,该组件似乎未呈现。

关于如何实现这一目标的任何想法?

css reactjs material-ui

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

标签 统计

css ×1

material-ui ×1

python-2.x ×1

python-3.x ×1

reactjs ×1