I found this python example online and I'd like to understand exactly how the number formatting works:
print "%.*g\t%.*g" % (xprecision, a, yprecision, b)
I can see by experimentation that this prints a (with precision xprecision), a tab and then b (with precision yprecision). So, as a simple example, if I run
print "%.*g\t%.*g" % (5, 2.23523523, 3, 12.353262)
then I get
2.2352 12.4
I understand how %g usually works. I also understand how the % generally works. What is confusing me in this example is the construct %.*g. How does the * work here? I can see that it is somehow taking the desired precision value and substituting it into the print expression, but why is that happening? Why does the precision number appear before the number being formatted in (xprecision, a...)?
Can someone break this down and explain it to me?