小编Qi *_*hen的帖子

用变量连接元组

我有一个元组x = (2,),我想添加一个变量y.我事先并不知道究竟是什么样的变量y.

y 可能:

  • 一个元组,在这种情况下我很乐意使用x+y,或者
  • 单个对象(通常是字符串或int),在这种情况下我应该使用x+(y,).

采用一种策略会在一半的时间内给我一个TypeError,而采用另一种策略会(2, (3, 4))在我想要的时候给我(2, 3, 4).

处理这个问题的最佳方法是什么?

python tuples concatenation

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

调用委托时NotImplementedException

我正在实现一个事件结构,以将信息从View传递给Presenter.在视图中,单击按钮时会调用以下代码:

private void alterCmpd1()
{
    EventHandler AlterEvent = AlterCompound1_Action;
    if (AlterEvent != null) AlterEvent(this, EventArgs.Empty);
}

public event EventHandler AlterCompound1_Action;
Run Code Online (Sandbox Code Playgroud)

出于某种原因,NotImplementedException总是出现在:

AlertEvent(this, EventArgs.Empty);
Run Code Online (Sandbox Code Playgroud)

有人可以帮我找出原因吗?

来自Presenter类的代码:

    public MainPresenter(IMainView view, IModel model)
    {
        this.view = view;
        this.view.AlterCompound1_Action += new EventHandler(view_AlterCompound1);
        this.model = model;
        view.Show();
    }

    void view_AlterCompound1(object sender, EventArgs e)
    {
        // I commented out this code, on the off
        // chance that it was affecting things. Still no luck.
    }
Run Code Online (Sandbox Code Playgroud)

c# delegates winforms

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

python logging.debug() 中长列表的性能损失

Python 中的评估有多懒惰?如果我的代码看起来像

logging.debug('My very long list: %s' % list(x for x in long_generator))

并且日志记录有效级别使得调试消息被忽略,我是否会因使用此行而导致性能损失?

python logging

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

标签 统计

python ×2

c# ×1

concatenation ×1

delegates ×1

logging ×1

tuples ×1

winforms ×1