print fmstr % str <= possible??

Ozone Hole near South Pole ozonehole2k at yahoo.com
Tue Jan 22 01:59:32 CET 2002


Hi,

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