[Python-3000] More PEP 3101 changes incoming (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Aug 14 03:10:42 CEST 2007


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



More information about the Python-3000 mailing list