how to repeat function definitions less

alex goretoy aleksandr.goretoy at gmail.com
Sat Mar 14 23:40:20 CET 2009


I'm doing this in my code, how to make it define all this functions for me
with lambda, I've been up for a while and cant seem to figure it out, whats
the most efficient way to do it? with lambda? how? thx

    def red(self,value,color='red',level='INFO'):
        self.write(value,color,level)
    def gold(self,value,color='gold',level='INFO'):
        self.write(value,color,level)
    def green(self,value,color='green',level='INFO'):
        self.write(value,color,level)
    def blue(self,value,color='blue',level='INFO'):
        self.write(value,color,level)
    def yellow(self,value,color='yellow',level='INFO'):
        self.write(value,color,level)
    def purple(self,value,color='purple',level='INFO'):
        self.write(value,color,level)
    def w_red(self,value,color='white_on_red',level='INFO'):
        self.write(value,color,level)
    def w_gold(self,value,color='white_on_gold',level='INFO'):
        self.write(value,color,level)
    def w(self,value,color="red",level="INFO"):
        self.write(value,color,level)
    def write(self,value,color="red",level="INFO"):
        """
        write - output message,take value string or list,color=""
        """
        self._hero(value,color,level)


-Alex Goretoy
http://www.goretoy.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090314/4d80e639/attachment.html>


More information about the Python-list mailing list