El 13/09/13 10:19, Paul McNett escribió:
On 9/13/13 6:06 AM, Ricardo Aráoz wrote:
If you want to specify the DataStructure, you need to also addField(). I've 
written a
addFieldsFromDataStructure() method for this.
Didn't know that method existed. I'll give it a try.
I don't think I ever posted it to Dabo. It goes like this:

     def addFieldsFromDataStructure(self):
         max_fill = 0
         for field in self.DataStructure:
             if field[3] is not None:
                 fill = len("%s.%s" % (field[3], field[4]))
                 max_fill = max(max_fill, fill)
         for field in self.DataStructure:
             fill = " " * (max_fill - len("%s.%s" % (field[3], field[4])))
             if field[3] is not None:
                 self.addField("%s.%s %sas %s" % (field[3], field[4],
                     fill, field[0]))

Most of the code has to do with indentation.


Simple is beautiful.
I do it this way :

        for field in self.DataStructure:
            alias = field[0]
            tabla = field[3]
            campo = field[4]
            if tabla:
                self.addField('{}.{}'.format(tabla, campo), alias)

If you'd like to go the 'table.field as alias' way, then replace the last line with "self.addField('{}.{} as {}'.format(tabla, campo, alias))".

If you want to indent just do "self.addField('{}.{} as {}'.format(tabla, campo, alias).rjust(40))".

If you want finer indenting (first line is just before the loop) :

totLen = max((len('{}.{}'.format(i[3], i[4])) for i in self.DataStructure))
...
..
.
self.addField('{}.{} as {}'.format(tabla, campo, alias).rjust(totLen))

_______________________________________________
Post Messages to: Dabo-users@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/52331820.20...@gmail.com

Reply via email to