Automatic Generation of Python Class Files

Fuzzyman fuzzyman at gmail.com
Mon Oct 29 17:04:10 EDT 2007


On Oct 22, 6:43 pm, Steven Bethard <steven.beth... at gmail.com> wrote:
> Sunburned Surveyor wrote:
> > Contents of input text file:
>
> > [Name]
> > Fire Breathing Dragon
>
> > [Properties]
> > Strength
> > Scariness
> > Endurance
>
> > [Methods]
> > eatMaiden argMaiden
> > fightKnight argKnight
>
> > Generated Python Class File:
>
> > def class FireBreathingDragon:
>
> >    def getStrength(self):
> >       """
> >       Docstring goes here.
>
> >       @return
> >       @rtype
> >       """
> >       return self.strength
>
> >    def setStrength(self, argStrength):
> >       """
> >       Docstring goes here.
>
> >       @param argStrength
> >       @ptype
> >       """
> >       return self.strength
>
> >    def eatMaiden(self, argMaiden):
> >       """
> >       Docstring goes here.
>
> >       @param argMaiden
> >       @ptype
> >       """
>
> This should instead generate::
>
> # Inherit from object. There's no reason to create old-style classes.


We recently had to change an object pipeline from new style classes to
old style. A lot of these objects were being created and the *extra
overhead* of new style classes was killing us. :-)

Michael
http://www.manning.com/foord






More information about the Python-list mailing list