小编nes*_*dis的帖子

Python属性描述符设计:为什么要复制而不是变异?

我在看内部Python如何实现属性描述符.根据property()描述符协议实现文档,为方便起见,在此处复制它:

class Property(object):
    "Emulate PyProperty_Type() in Objects/descrobject.c"

    def __init__(self, fget=None, fset=None, fdel=None, doc=None):
        self.fget = fget
        self.fset = fset
        self.fdel = fdel
        if doc is None and fget is not None:
            doc = fget.__doc__
        self.__doc__ = doc

    def __get__(self, obj, objtype=None):
        if obj is None:
            return self
        if self.fget is None:
            raise AttributeError("unreadable attribute")
        return self.fget(obj)

    def __set__(self, obj, value):
        if self.fset is None:
            raise AttributeError("can't set attribute")
        self.fset(obj, value)

    def __delete__(self, obj):
        if self.fdel is …
Run Code Online (Sandbox Code Playgroud)

python inheritance properties mutators

28
推荐指数
3
解决办法
720
查看次数

从结构指令发送到父组件的事件不起作用

作为问题的后续问题:从Directive到Parent元素发出事件:Angular2

看起来当结构指令发出事件时,父组件不会接收它.

@Directive({ selector: '[appWidget]' })
export class WidgetDirective implements OnInit{
@Output() wdgInit: EventEmitter<any> = new EventEmitter();
@Input() set appWidget (wdg: any) {
    //display stuff
}
ngOnInit {
   this.wdgInit.emit();
}
Run Code Online (Sandbox Code Playgroud)

widget.component.html:

  <ng-container *ngFor="let wdg of widgets">      
  <div *appTwitterWidget="wdg" >
  <ng-container>
Run Code Online (Sandbox Code Playgroud)

widgetContainer.component.html:

 <app-widget [widgets]="widgetList" (wdgInit)="containerDoSomthing()"></app-widget>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我发现从不调用containerDoSomthing().

javascript typescript angular-directive angular

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

在pip中指定模块所需的最小python版本

有没有办法指定在pip中安装模块所需的最小python版本?

我正在尝试将包发布到pypi.

python setup.py sdist upload -r pypi
Run Code Online (Sandbox Code Playgroud)

是我正在使用的命令.但是在setup.py中没有办法指定运行此模块需要最小的python版本(在我的例子中是python 3.5).

python pip pypi

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