python sqlite 查询表的字段名 列名

获得查询结果表的列名:

 

[python]  view plain copy print ?
 
  1. db = sqlite.connect('data.db')  
  2. cur = db.cursor()  
  3. cur.execute("select * from table")  
  4. col_name_list = [tuple[0for tuple in cur.description]  
  5. print col_name_list  


获得所有列名:

 

 

[python]  view plain copy print ?
 
  1. cur.execute("PRAGMA table_info(table)")  
  2. print cur.fetchall()  


 

posted on 2013-09-22 20:36  you Richer  阅读(1973)  评论(0编辑  收藏  举报