How do I create a CSV file from database in Python?

前端 未结 8 2026
南方客
南方客 2020-12-05 00:05

I have a Sqlite 3 and/or MySQL table named \"clients\"..

Using python 2.6, How do I create a csv file named Clients100914.csv with headers? excel dialect...

8条回答
  •  Happy的楠姐
    2020-12-05 01:01

    You can easily create it manually, writing a file with a chosen separator. You can also use csv module.

    If it's from database you can alo just use a query from your sqlite client :

    sqlite  < queryfile.sql > output.csv
    

    Which will create a csv file with tab separator.

提交回复
热议问题