Eric Smith wrote:
> In order for me to write the __format__ function in MyInt, I have to
> know if the specifier is in fact an int specifier.
>
> class MyInt:
> def __format__(self, spec):
> if int.is_int_specifier(spec):
> return int(self).__format__(spec)
> return "MyInt instance with custom specifier " + spec
I would do this the other way around, i.e. first look
to see whether the spec is one that MyInt wants to handle
specially, and if not, *assume* that it's an int specifier.
E.g. if MyInt defines a new "m" format:
def __format__(self, spec):
if spec.startswith("m"):
return self.do_my_formatting(spec)
else:
return int(self).__format__(spec)
--
Greg
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com