I have a function that both returns a value and does some printing. Schematically:
def func(x):
print "You're using this function"
return x**2
There are two different ways in which I might want to use the function, one is to do the printing so that I can read the info, but another one is to both print and store the result in a variable:
>>> func(2)
You're using this function
4
>>> a=func(2)
You're using this function
I would like to prevent the first usage from printing 4
. Can I do this modifying the function definition somehow?
Edit
Since people seem to have some trouble understanding where I'm coming from, this is my function's output when I use it interactively:
>>> ela_dist(c_voigt, rotate = True)
************************** R E S U L T S **************************
Results with rotation optimization
Symmetry Euclidean distance Angles tx, ty, tz
-------- ------------------ -------------------------------
iso 139.65 GPa n/a n/a n/a deg.
cub 83.66 GPa -1.89 -1.83 6.37 deg.
hex 110.23 GPa -2.14 -4.22 n/a deg.
3 102.16 GPa -3.27 -6.94 n/a deg.
32 102.16 GPa -3.27 -6.94 n/a deg.
4 82.32 GPa -2.52 -1.15 2.14 deg.
4mm 82.32 GPa -2.52 -1.15 6.31 deg.
ort 78.00 GPa -3.05 -1.71 7.87 deg.
mon 62.62 GPa -2.85 0.76 7.62 deg.
************************** R E S U L T S **************************
[['iso', 139.65433517558037, 0.0, 0.0, 0.0], ['cub', 83.663957459095329, -1.8878916427147878, -1.8303975226851734, 6.3671511063645525], ['hex', 110.23296814646618, -2.1378994103876803, -4.2246840445795071, 0.20038249224556773], ['3', 102.16396472738577, -3.2709875018178636, -6.9354445747734825, 5.1898595103729814], ['32', 102.16396472738596, -3.2709866369782259, -6.9354442259896656, -20.03283399363794], ['4', 82.321990809120038, -2.5218897967148739, -1.1525909395834488, 2.1400405876841635], ['4mm', 82.32199080912001, -2.5218897552576087, -1.1525909978835307, 6.3069829557712076], ['ort', 78.001968057183262, -3.0530030281994716, -1.7132006819033545, 7.8685738019737688], ['mon', 62.623413013297196, -2.8503971823612497, 0.75895564714111607, 7.6204664688915926]]
So I am generating a "nice" output and then there is this long list with results that I do not want to show. However, I want the user to have to possibility to store the results in a variable for later use.
See Question&Answers more detail:
os