print fmstr % str <= possible??

Ozone Hole near South Pole ozonehole2k at
Mon Jan 21 19:59:32 EST 2002


If I want to print some numerical data, I need to:
print "The answer is %2.3f" % ans

Is that possible to pass a fmtstr to do something like this
def myprint(fmtstr,ans):
  print fmtstr % ans

myprint("The x pos is %2.3", x) 
myprint("The y pos is %5.3", y) 

I know the above will not work.  What's the correct way to do this?

More information about the Python-list mailing list