Search code examples
pythonlistpeeweebrightway

Why a list of activities can't be appended to another list of activities in Brightway2?


I have a two list of activities that I would like to append one to another. But somehow this does not work and the result turns into a NoneType obj. Why is that so?

This can be reproduced easily by the following:

type([Database("whatever database").random()].append([Database("whatever database").random()]))

I have checked the type for both lists and ensure they are lists. Within each list, the type of each element is bw2data.backends.peewee.proxies.Activity.


Solution

  • [].append(something) will return None and that is why you see NoneType object. Try this approach:

    data = [Database("whatever database").random()]
    data.append([Database("whateverdatabase").random()])
    print(type(data)) # list
    print(len(data))  # 2
    

    To verify your new list contains that which you appended, you can use print(data) which should return Database("whatever database").random() twice.