# python calculator using python variable

**URL:** https://discourse.paraview.org/t/python-calculator-using-python-variable/3018
**Category:** ParaView Support
**Created:** [November 21, 2019, 2:31pm UTC](https://discourse.paraview.org/t/python-calculator-using-python-variable/3018 "2019-11-21T14:31:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nopech](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nopech/32/2137_2.png) [@nopech](https://discourse.paraview.org/u/nopech)
#### Post date: [November 21, 2019, 2:31pm UTC](https://discourse.paraview.org/t/python-calculator-using-python-variable/3018/1 "2019-11-21T14:31:54Z")

</div>

Hello everyone

I just spent more than one hour trying to figure out something that seemed so simple to me:

I’m using the python calculator in a python script to multiply multiple PointData. This looks something like this:  
pCalcQ = PythonCalculator(Input=[calcU, readerRho, pCalcH])  
pCalcQ.ArrayName = “Qflux”  
pCalcQ.Expression = ‘inputs[0].PointData[“U\_Normal”]\*inputs[1].PointData[“density”]\*inputs[2].PointData[“H”]’

However, now I want to subtract a scalar value from each data point. The scalar value is stored in a variable called hRef.  
Subtraction of a scalar value works fine like this:  
pCalcQ.Expression = ‘inputs[0].PointData[“U\_Normal”]\*inputs[1].PointData[“density”]\*inputs[2].PointData[“H”]-2’  
but it does not withe the variable:  
pCalcQ.Expression = ‘inputs[0].PointData[“U\_Normal”]\*inputs[1].PointData[“density”]\*inputs[2].PointData[“H”]-hRef’

How to do that? I’ve tried to define the variable as input of the python calculator but that is also not working.

Thank you, regards  
nopech

---

<div class="post-metadata">

### Author: ![nopech](https://discourse.paraview.org/user_avatar/discourse.paraview.org/nopech/32/2137_2.png) [@nopech](https://discourse.paraview.org/u/nopech)
#### Post date: [November 21, 2019, 2:44pm UTC](https://discourse.paraview.org/t/python-calculator-using-python-variable/3018/2 "2019-11-21T14:44:50Z")

</div>

Oke, nevermind. The solution came to my mind as soon as I posted this:

Of course if the expression is a string, the float value of my variable has to be converted to a string.  
pCalcQ.Expression = ‘inputs[0].PointData[“U\_Normal”]\*inputs[1].PointData[“density”]\*inputs[2].PointData[“H”]-’ + str(hRef)

Works fine.

Cheers, nopech
