小编Pap*_*K24的帖子

在SQLAlchemy中查询属性列表而不是元组

我正在查询模型的ID,并获取(int,)元组列表而不是id列表.有没有办法直接查询属性?

result = session.query(MyModel.id).all()
Run Code Online (Sandbox Code Playgroud)

我意识到这是可能的

results = [r for (r,) in results]
Run Code Online (Sandbox Code Playgroud)

查询是否可以直接返回该表单,而不必自己处理它?

python sqlalchemy

19
推荐指数
3
解决办法
8184
查看次数

在调用基础构造函数之前计算值

有没有什么方法可以在后代类构造函数的末尾调用超级构造函数?

它适用于Java,但在C#中,关键字base似乎不等同于Java的超级.

例:

class CommonChest : BasicKeyChest
{
    public CommonChest()
    {
        Random rnd = new Random();
        int key = rnd.Next(1, 6);
        int coins = rnd.Next(70, 121);
        super(key, coins, "Common");
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# oop

4
推荐指数
2
解决办法
1069
查看次数

让 Mypy 接受解压的 dict

我的 mypy 有问题

我有这样的代码:

func(arg1, arg2, arg3=0.0, arg4=0.0)
# type: (float, float, float, float) -> float
# do something and return float.

dict_with_other_arguments = {arg3: 0.5, arg4: 1.4}
a = func(arg1, arg2, **dict_with_other_arguments)
Run Code Online (Sandbox Code Playgroud)

问题是 mypy 不检查字典中的类型,而是我得到如下错误: error: Argument 3 to "func" has incompatible type "**Dict[str, float]"; 预期的“浮动”

任何想法如何在不更改代码的情况下解决此问题?

python dictionary mypy

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

标签 统计

python ×2

.net ×1

c# ×1

dictionary ×1

mypy ×1

oop ×1

sqlalchemy ×1