小编Rad*_*nik的帖子

Python`map`和参数解包

我知道

map(function, arguments)
Run Code Online (Sandbox Code Playgroud)

相当于

for argument in arguments:
    function(argument)
Run Code Online (Sandbox Code Playgroud)

是否可以使用map功能执行以下操作?

for arg, kwargs in arguments:
    function(arg, **kwargs)
Run Code Online (Sandbox Code Playgroud)

python map-function

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

使用__的Python"隐藏"方法

今天我看到 - python添加_$CLASSNAME$到名称为的方法__.

简单的例子:

>>> class A:  
...     def a(self):  
...         self.b()  
...     def b(self):  
...         print('A.b')  
...           
>>> class B(A):  
...     def b(self):  
...         print('B.b')  
...           
>>> B().a()  
B.b
Run Code Online (Sandbox Code Playgroud)

那项工作,但是:

>>> class A:  
...     def a(self):  
...         self.__b()  
...     def __b(self):  
...         print('A.b')  
...           
>>> class B(A):  
...     def __b(self):  
...         print('B.b')  
...           
>>> B().a()  
A.b
Run Code Online (Sandbox Code Playgroud)

为什么?我不知道,所以我给了它.这里是:

>>> print([fn for fn in dir(B) if fn[-2:] != '__'])
['_A__b', '_B__b', 'a']
Run Code Online (Sandbox Code Playgroud)

为什么python这样做?有办法绕过那个吗?

python oop inheritance

5
推荐指数
2
解决办法
8687
查看次数

Python装饰理论

我对Python中的干净thory有疑问.什么时候:

@decorator_func
def func(bla, alba):
    pass
Run Code Online (Sandbox Code Playgroud)

相当于:

def func(bla, alba):
    pass
func = decorator_func(func)
Run Code Online (Sandbox Code Playgroud)

所以:

@decorator_func(aaa, bar)
def func(bla, alba):
    pass
Run Code Online (Sandbox Code Playgroud)

等于...?

python theory decorator

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

Random data in defaultProps

I'm using React for quite a long time and I've encountered an interesting problem: basically, I want to use defaultProps as fallbackProps - that's what they are for, but there's one difficulty - both defaultProps property from stateless / class extend Component API and cached getDefaultProps() from React.createClass API are immutable (and constant).

Example:

var ExampleComponent = React.createClass({
    getDefaultProps: function () {
        return {
            number: Math.random()
        };
    }
    // ...
});

// or equivalent with ES6 classes

class ExampleComponent extends …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

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

如何以编程方式添加 imageView 宽度/高度?

我如何更改width/heightUIImageView. 我有很多不同的图片width/height,我希望它们以 imageView 的大小显示。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
    let city = nicosiaPlaces [indexPath.row]
    cell?.textLabel?.text = city
    cell?.imageView?.image = UIImage(named: city)
    cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
    return cell!
}
Run Code Online (Sandbox Code Playgroud)

我想让这行代码工作:

cell?.imageView?.frame.size = CGSize(width: 10, height: 10)
Run Code Online (Sandbox Code Playgroud)

uitableview uiimageview image-size swift

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

Ruby中的自我意味着什么?

ruby self代表什么?它是什么?这是什么意思?有人可以向我解释一下吗?简单来说,请问它在课堂上的功能是什么?

class MyClass
   def method.self
   end
end
Run Code Online (Sandbox Code Playgroud)

ruby self

-3
推荐指数
1
解决办法
5645
查看次数