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

前端 未结 8 2032
南方客
南方客 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条回答
  •  一生所求
    2020-12-05 00:48

    unless i'm missing something, you just want to do something like so...

    f = open("somefile.csv")
    f.writelines("header_row")
    

    logic to write lines to file (you may need to organize values and add comms or pipes etc...)

    f.close()
    

提交回复
热议问题