[Tutor] Looking for Constructs to Remove Redundant Code
Ilias Lazaridis
ilias at lazaridis.com
Sat Apr 1 02:48:19 CEST 2006
Kent Johnson wrote:
...
Thank you for your comments. I realize that my request was not very
clear. I make a 2nd attemp, more simplified:
I have this python code:
class Car(BaseClass) :
manufacturer = stringFactory()
model = stringFactory()
modelYear = integerFactory()
def __str__(self):
return '%s %s %s' % (self.modelYear, self.manufacturer,
self.model)
def stringFactory(self)
s = String() # creates a string object
#... # does several things
return s # returns the string object
-
and would like to see it e.g. this way:
class Car(BaseClass):
manufacturer = stringFactory(2)
model = stringFactory(3)
modelYear = integerFactory(1)
def stringFactory(self, position)
s = String() # creates a string object
... # does several things
# creates somehow the __str__ functionality...
return s # returns the string object
-
hope this is now more clear.
.
--
http://lazaridis.com
More information about the Tutor
mailing list