[Tutor] Looking for Constructs to Remove Redundant Code

Ilias Lazaridis ilias at lazaridis.com
Fri Mar 31 14:56:25 CEST 2006


I have this python code

class Car:
     """Type of car."""

     manufacturer = f.string()
     model = f.string()
     modelYear = f.integer()

     _key(manufacturer, model, modelYear)

     def __str__(self):
         return '%s %s %s' % (self.modelYear, self.manufacturer, self.model)

-

and would like to see it e.g. this way:

class Car:
     """Type of car."""

     manufacturer = f.string(true, str=2)
     model = f.string(true, str=3)
     modelYear = f.integer(true, str=1)

-

how would the factory method look like?

def string(self, key, str )
     # create somehow the __str__ function
     # create somehow the key

.

-- 
http://lazaridis.com



More information about the Tutor mailing list