Comments (5)
Original comment by Benjamin W. Portner (Bitbucket: pommespapst, GitHub: pommespapst).
Better-formatted code:
#!python
oActivity = bw.Database('some_db').search("some_activity")[0]
oExchange = list(oActivity.exchanges())[1]
oExchange["amount"]
# 0
oExchange["amount"] = 1
oExchange["amount"]
# still 0
from brightway2.
Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).
Sorry, that is frustrating! I can't reproduce this:
#!python
In [6]: db = Database("ecoinvent 3.5 cutoff")
In [7]: exc = list(db.random().exchanges())[0]
In [8]: exc['amount']
Out[8]: 0.000277
In [9]: exc['amount'] = 1
In [10]: exc['amount']
Out[10]: 1
Some things to try:
- Make sure your version of
bw2data
is up to date - latest is 3.4.4. - Make sure you are getting an actual activity and exchange (not sure how this wouldn't be the case, but check anyway)
- If you are loading the exchange in the second half, note that your changes will only be written to the database if you call
oExchange.save()
after you make your modifications.
from brightway2.
Original comment by Benjamin W. Portner (Bitbucket: pommespapst, GitHub: pommespapst).
Looks like the error occurs if the handle to the exchange is not saved:
#!python
oAct = bw.Database('ecoinvent 3.5 APOS').random()
# does not work
list(oAct.exchanges())[0]["amount"]
list(oAct.exchanges())[0]["amount"] = 3
list(oAct.exchanges())[0]["amount"]
# works
oExc = list(oAct.exchanges())[0]
oExc["amount"]
oExc["amount"] = 3
oExc["amount"]
from brightway2.
Original comment by Chris Mutel (Bitbucket: cmutel, GitHub: cmutel).
There are two important details here:
list(oAct.exchanges())[0]["amount"]
will retrieve the exchanges from the database each time, and there is no guarantee that they are in the same order (by default database queries have no defined order unless you specify one). I am not sure if Brightway gives a default order - by guess is yes - but in general SQL queries don't unless you specifyORDER BY
.list(oAct.exchanges())[0]["amount"]
also won't work the second time because you are recreating the object each time. The changes you make in the first instance are not saved, and so disappear. It is the same as:
#!python
In [1]: class A:
...: pass
...:
In [2]: a = A()
In [3]: a.foo = "bar"
In [4]: a = A()
In [5]: a.foo
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-5-031223489f27> in <module>()
----> 1 a.foo
AttributeError: 'A' object has no attribute 'foo'
from brightway2.
Original comment by Benjamin W. Portner (Bitbucket: pommespapst, GitHub: pommespapst).
Thanks for the clarification!
Concerning the order of exchanges: it is changing every time indeed. Thanks for the hint!
from brightway2.
Related Issues (20)
- Biosphere3 version made clear
- bw2io.errors.MultiprocessingError HOT 1
- Ecospold2 importer issue with versions 2.1, 2.2, 2.4 (ecoinvent 3.6 and ecoinvent 3.8) HOT 1
- Unable to clone repository due to invalid path (possibly forbidden character (?) in file name)
- Brightway tutorial not working on fresh install HOT 3
- Unable to create new project. "IntegrityError: NOT NULL constraint failed: projectdataset.full_hash" HOT 6
- numpy.bool is deprecated and is removed from numpy-1.24.x HOT 1
- Trying to create activity parameters through imports of databases
- Biosphere exchange in- and outputs wrong way around with ecoinvent 3.9.1? HOT 1
- Importing ILCD-EPDs from Ökobaudat
- Export inventory results from uncertainty analysis
- Top activities not working for upstream exploration of hotspots HOT 1
- LeastSquaresLCA throwing NonsquareTechnoSphere
- Wrong units for ReCiPe endpoint categories
- I cannot install brightway 2 with anaconda HOT 3
- how to use brightway 2 to import lcia file. {http://www.EcoInvent.org/EcoSpold02}impactIndicator raise ValueError ValueError
- cannot install the brightway 2 in anaconda
- Cannot import brightway2 in Jupyter notebook HOT 3
- ExcelImporter write_database issue
- Trace back error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brightway2.