Export a .csv file using web.py – (python:))

December 22nd, 2009 No Comments   Posted in Scripts for Testing

This script is for Exporting a csv file and get the browser to recognize that its a csv file and popups the download window with web.py. Lets say we have a database with a table called users and you want to create a csv file that contains all the users with their names and id’s here is how you do it.

class export:
def GET(self):
i = web.input()

users = web.select(’users‘, vars=locals())

csv = []
csv.append(”id,name\n“)
for user in users:
row = []
row.append(user.id)
row.append(user.name)

csv.append(”,“.join(row))
#writer.writerow(row)

#f.close()

web.header(’Content-Type‘,’text/csv‘)
web.header(’Content-disposition‘, ‘attachment; filename=export.csv‘)
print “”.join(csv)
return

  • Share/Bookmark

Tags: ,

Back after a Break !!!

December 22nd, 2009 No Comments   Posted in Official Memo

Well, I have been off from the Blog and the Net for a while, had to take an involuntary break from everything due to other commitments :) !

But as promised to a lot of you, I am adding some articles that I had written and researched while on the break. So here is the List:

More »

  • Share/Bookmark
Get Adobe Flash playerPlugin by wpburn.com wordpress themes