Factory class with abstractmethod
Question: I've created a factory class called `FitFunction` that adds a whole bunch of
stuff beyond what I've shown. The label method `pretty_string` is supposed to
just return the string as written. When I run this file, it prints a string
that is as useful as the `repr`. Does someone know how I would go about
implementing this?

    
    
    #!/usr/bin/env python
    
    from __future__ import print_function, absolute_import
    
    import abc
    import types
    import numpy as np
    
    class FitFunction(object):
    
        def __init__(self, python_function):
    
            assert isinstance(python_function, types.FunctionType)
            self._py_function = python_function
    
        @abc.abstractmethod
        def pretty_string():
            r"""
            Return some pretty string.
            """
    
    
    class Gaussian(FitFunction):
    
    
        def __init__(self):
    
            def gaussian(x, mu, sigma, A):
                coeff = (_np.sqrt(2.0 * _np.pi) * sigma)**(-1.0)
                arg   = -.5 * (((x - mu) / sigma)**2.0)
                return A * coeff * _np.exp(arg)
    
            FitFunction.__init__(self, gaussian)
    
            @staticmethod
            def pretty_string():
                return "1D Gaussian"
    
    
    if __name__ == "__main__":
    
        print("Gaussian.pretty_string: %s" % Gaussian().pretty_string() )
    

I subclass `FitFunction` to create `Gaussian` because I apply `Gaussian` to
many different data sets with the same parameters so that I can compare the
output.

For reference, this is what happens when I execute the file:

    
    
    me$ ./FitFunction_SO_test.py 
    Gaussian.pretty_string: <bound method Gaussian.pretty_string of <__main__.Gaussian object at 0x1005e2f90>>
    

I'm looking for the following result:

    
    
    me$ ./FitFunction_SO_test.py 
    Traceback (most recent call last):
      File "./FitFunction_SO_test.py", line 43, in <module>
        print("Gaussian.pretty_string: %s" % Gaussian().pretty_string())
    TypeError: pretty_string() takes no arguments (1 given)
    


Answer: Use:

    
    
    print("Gaussian.pretty_string: %s" % Gaussian.pretty_string())
    

Or else you are printing the `repr` of the _method_ , not the _result of
calling the method_ , which is the string you are looking for.

