小编Vid*_*ain的帖子

如何在python中创建一个对象数组?

当我在python中创建一个对象数组时,初始化为数组的值不是预期的

我定义的类是

class piece:
    x = 0
    y = 0
    rank = ""
    life = True
    family = ""
    pic = ""

    def __init__(self, x_position, y_position, p_rank, p_family):
        piece.x = x_position
        piece.y = y_position
        piece.rank = p_rank
        piece.family = p_family
Run Code Online (Sandbox Code Playgroud)

当我初始化数组

pie = []
pie.append(piece(25, 25, "p", "black"))
pie.append(piece(75, 25, "p", "black"))
pie.append(piece(125, 25, "p", "black"))

print(pie[1].x)
Run Code Online (Sandbox Code Playgroud)

输出为125,预期输出为75

python arrays object

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

Mongodb 用不同的值更新多个文档

我一直在尝试updatemany与猫鼬一起使用。我想使用对象数组更新数据库中的值。

[
            {
                "variantId": "5e1760fbdfaf28038242d676",
                "quantity": 5

            },
            {
                    "variantId": "5e17e67b73a34d53160c7252",
                    "quantity": 13
            }
            ]
Run Code Online (Sandbox Code Playgroud)

我想使用 variantId 作为过滤器。模型架构是:

let variantSchema = new mongoose.Schema({
    variantName: String,
    stocks: {
        type: Number,
        min: 0
    },
    regularPrice: {
        type: Number,
        required: true
    },
    salePrice: {
        type: Number,
        required: true
    }
})
Run Code Online (Sandbox Code Playgroud)

我想使用 variantId 过滤模型,然后减少库存。

mongoose mongodb node.js mongoose-schema

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

标签 统计

arrays ×1

mongodb ×1

mongoose ×1

mongoose-schema ×1

node.js ×1

object ×1

python ×1