class FormatFloat(FormatFormatStr):
def __init__(self, precision=4, scale=1.):
FormatFormatStr.__init__(self, '%%1.%df'%precision)
self.precision = precision
self.scale = scale
def toval(self, x):
if x is not None:
x = x * self.scale
return x
def fromstr(self, s):
return float(s)/self.scale
The part that confuses me is this part
FormatFormatStr.__init__(self, '%%1.%df'%precision)
does this mean that the precision gets entered twice before the 1 and once before df? Does df stand for anything that you know of? I don't see it elsewhere even in its ancestors as can be seen here:
class FormatFormatStr(FormatObj):
def __init__(self, fmt):
self.fmt = fmt
def tostr(self, x):
if x is None: return 'None'
return self.fmt%self.toval(x)
class FormatObj:
def tostr(self, x):
return self.toval(x)
def toval(self, x):
return str(x)
def fromstr(self, s):
return s
also, I put this into my Ipython and get this:
In [53]: x = FormatFloat(.234324234325435)
In [54]: x
Out[54]: <matplotlib.mlab.FormatFloat instance at 0x939d4ec>
I figured that it would reduce precision to 4 and scale to 1. But instead it gets stored somewhere in my memory. Can I retrieve it to see what it does to the number?
Thanks everyone you're very helpful!