I think that your csv output should have a fixed column length. The way you are trying to create the file would produce variable column length for each row, unless you provide a way of adding the blank fields.
Row objects have as_dict method. You could use this method to map row data to a new table and create the csv file from it. On 21 ene, 04:04, Adi <adnan.smajlo...@gmail.com> wrote: > I am trying to export all rows from two tables, (e.g. purchase orders, and > items) into a csv file, but if possible would like to export a single row > per each purchase order (with belonging items divided into separate columns > of the same row). I'm using MySQL, if it makes the difference. > > I read some comments about using the Expression or a function (from > gluon.sql import Expression), but don't know how to go about it. Any advise? > > Thanks, > Adnan > > >>> rows = db(db.purchase_order.id>0).select(db.purchase_order.po_number, > > db.item.id, left=db.item.on(db.purchase_order.id==db.item.po_id)) > > >>> print rows > > results: > purchase_order.po_number,item.id > 201201120001,31 > 201201120001,41 > 201201120001,51 > 201201120001,61 > 201201160004,111 > 201201170005,151 > 201201006,161 > > would prefer to have it like this: > 201201120001,31,41,51,61 > 201201160004,111 > 201201170005,151 > 201201006,161