You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Brightway25创建活动后production()返回空列表的原因咨询

问题原因

在Brightway25中,reference product和production amount只是活动的属性标记,用来定义该活动的核心产出是什么,但它们不会自动生成对应的生产交换流。act.production()方法返回的是活动的交换对象集合,只有显式添加的交换才会被包含在内。

解决方案

有两种正确的方式创建包含生产输出的活动:

方法1:创建活动时直接定义交换流

在new_activity的参数中加入exchanges列表,明确声明生产交换:

act = db.new_activity(
    **{
        'code': 'test',
        'location': 'GLO',
        'name': 'activity name',
        'reference product': 'output product',
        'unit': 'kg',
        'exchanges': [
            {
                'amount': 1,
                'input': ('你的数据库名称', 'test'),  # 替换为实际数据库名
                'type': 'production',
                'name': 'output product',
                'unit': 'kg'
            }
        ]
    }
)
act.save()

方法2:创建活动后手动添加生产交换

先创建活动,再通过act.new_exchange()添加生产流:

act = db.new_activity(
    **{
        'code': 'test',
        'location': 'GLO',
        'name': 'activity name',
        'reference product': 'output product',
        'unit': 'kg',
    }
)

# 添加生产交换
prod_exchange = act.new_exchange(
    amount=1,
    input=(db.name, act['code']),
    type='production',
    name='output product',
    unit='kg'
)
prod_exchange.save()
act.save()

验证:执行上述任一方法后,运行len([i for i in act.production()])会返回1,说明生产交换已成功创建。

内容的提问来源于stack exchange,提问作者Stücke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 11:27:31