On 10/22/07, Sunburned Surveyor <[EMAIL PROTECTED]> wrote: > On Oct 22, 10:26 am, "Chris Mellon" <[EMAIL PROTECTED]> wrote: > > On 10/22/07, Sunburned Surveyor <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > I was thinking of a way I could make writing Python Class Files a > > > little less painful. I was considering a Ptyhon script that read a > > > file with a list of property names and method names and then generated > > > a skeleton class file. > > > > > I was even thinking of automatically generating the shell for doc > > > strings and epydoc tags. > > > > > Is there existing scripts that do something like this? If not, I will > > > try to come up with something. If I'm sucessful I'll release the code > > > under the GPL and will report back to the list. > > > > > However, I thought I would check here first so that I don't reinvent > > > the wheel. > > > > > Thanks, > > > > > Scott Huey > > > > I can't think of a single reason why you would ever want to do this, > > since your "list of method and property names" would be just as > > verbose as just typing the actual python code. > > > > Auto generated documentation stubs are considered harmful because they > > take the place of real documentation.- Hide quoted text - > > > > - Show quoted text - > > Chris, > > You wrote: " can't think of a single reason why you would ever want to > do this, > since your "list of method and property names" would be just as > verbose as just typing the actual python code." > > I don't think I understand how this would be the same amount of > typing. Consider the following example that would generate a Monster > class file from an input text file (I only did one property and method > in generated class file.): > > 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 > """ >
Your getters/setters are useless (Python isn't Java) and so are the docstrings, because you have to write them over again anyway. Removing them results in 3 lines of code, quite a bit shorter than your input file, and it doesn't have any of the quite well known issues with this sort of boiler plate code generation. -- http://mail.python.org/mailman/listinfo/python-list