Well, and that's a good (and a bad) thing... Note that returning str or select result calls a bunch of library things, and represents this as a CSV for you. (see gluon/sql.py/export_to_csv_file() ).
While you may not have trouble with it (and most people, most of the time won't), also note that this uses the csv library, and with default settings - which (among other things) include "\r\n" for newlines... (see http://docs.python.org/library/csv.html#csv-fmt-params Dialect.lineterminator) At some point we need to wrap the csv library in a class, so that web2py applications will be able to affect settings. As it is now, you can't really do that - so if defaults work, you're great; if not... ugh! this is a minor thing for now, just some of the "cobwebs" in corners that should get cleaned up at some point... On Tue, Apr 21, 2009 at 10:59 AM, Hans < johann.scheibelho...@easytouch-edv.com> wrote: > > WOW Massimo! That's almost too simple to believe it ;-) > > def my_exporter(): > response.headers['Content-Type']='text/x-csv' > response.headers['Content-Disposition']='attachment; > filename=yourpreferredfilename.csv' > return str(db(...).select(...)) > > On Apr 21, 4:57 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > the str(..) in str(db(...).select(...)) converts the result of the > > slect into CSV. > > > > when you call the action "http://..../my_exporter" it returns a text > > page containing CSV. > > > > If you want the browser to automatically save it in a file you may > > want to add two lines: > > > > def my_exporter(): > > response.headers['Content-Type']='text/x-csv' > > response.headers['Content-Disposition']='attachment; > > filename=yourpreferredfilename.csv" ' > > return str(db(...).select(...)) > > > > Massimo > > > > On 21 Apr, 09:38, Hans <johann.scheibelho...@easytouch-edv.com> wrote: > > > > > how do I get my_exporter() into csv? is there a web2py function which > > > can be called? > > > > > On Apr 21, 4:17 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > > > def my_exporter(): > > > > return str(db(...).select(...)) > > > > > > On 21 Apr, 08:52, Hans <johann.scheibelho...@easytouch-edv.com> > wrote: > > > > > > > I would like to make a controller function that does csv export of > a > > > > > join select (similar like SQL below but into csv - temporary table > ok > > > > > if necessary) . How can this be done in web2py? > > > > > > > SELECT Persons.LastName,Orders.OrderNo INTO Persons_Order_Backup > FROM > > > > > Persons INNER JOIN Orders ON Persons.P_Id=Orders.P_Id > > > > > > > Thanks, > > > > > Hans > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---