# How to store output from "ampl.display(\<\>)" in a python variable

**URL:** <https://discuss.ampl.com/t/how-to-store-output-from-ampl-display-in-a-python-variable/560>\
**Category:** Support\
**Tags:** python\
**Created:** [May 17, 2023, 5:56am UTC](https://discuss.ampl.com/t/how-to-store-output-from-ampl-display-in-a-python-variable/560 "2023-05-17T05:56:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bhartendu\_Awasthi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/bhartendu_awasthi/32/277_2.png) [@Bhartendu\_Awasthi](https://discuss.ampl.com/u/Bhartendu_Awasthi)\
**Post date:** [May 17, 2023, 5:56am UTC](https://discuss.ampl.com/t/how-to-store-output-from-ampl-display-in-a-python-variable/560/1 "2023-05-17T05:56:13Z")

</div>

display feature in AMPL is very neat. Is it possible to store the value of the resolved expression in a python variable. For instance please see below command

`x = ampl.display("sum {i in MONTHS, j in PRODUCTS} sell[i,j];")`  
shows below in python console  
`sum{i in MONTHS, j in PRODUCTS} sell[i,j] = 11588.6`

can I store 11588.6 somehow in a python variable ? When the expression resolves, the type of `x` is `None`.

Thanks  
Bhartendu

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [May 17, 2023, 9:40pm UTC](https://discuss.ampl.com/t/how-to-store-output-from-ampl-display-in-a-python-variable/560/2 "2023-05-17T21:40:19Z")

</div>

Hi @Bhartendu_Awasthi,

You can use `AMPL.get_value` for that:

```python
x = ampl.get_value("sum {i in MONTHS, j in PRODUCTS} sell[i,j]")

```

There is also `AMPL.get_data` for retrieving tabular expressions (e.g. `solution = ampl.get_data("{p in PEOPLE, g in GIFTS: x[p, g] > 0} x[p, g]").to_pandas()`)

---

<div class="post-metadata">

**Author:** ![Bhartendu\_Awasthi](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/bhartendu_awasthi/32/277_2.png) [@Bhartendu\_Awasthi](https://discuss.ampl.com/u/Bhartendu_Awasthi)\
**Post date:** [May 18, 2023, 2:11am UTC](https://discuss.ampl.com/t/how-to-store-output-from-ampl-display-in-a-python-variable/560/3 "2023-05-18T02:11:19Z")

</div>

Thank you very much @fdabrandao . Perhaps I need to look into AMPL python’s API documentation more.

Regards  
Bhartendu

---

<div class="post-metadata">

**Author:** ![fdabrandao](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.ampl.com/fdabrandao/32/63_2.png) [@fdabrandao](https://discuss.ampl.com/u/fdabrandao)\
**Post date:** [May 18, 2023, 11:12am UTC](https://discuss.ampl.com/t/how-to-store-output-from-ampl-display-in-a-python-variable/560/4 "2023-05-18T11:12:02Z")

</div>

No problem. Please fell free to ask any questions here, it helps us to notice what we may not be highlighting well in the documentation.
