欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

如何進行對Python操作方法的說明

今天就跟大家聊聊有關(guān)如何進行對Python操作方法的說明,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

我們提供的服務(wù)有:成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、樺南ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的樺南網(wǎng)站制作公司

MySQL是一個優(yōu)秀的開源數(shù)據(jù)庫,它現(xiàn)在的應(yīng)用非常的廣泛,因此很有必要簡單的介紹一下用python操作mysql數(shù)據(jù)庫的方法。Python操作數(shù)據(jù)庫需要安裝一個第三方的模塊。

由于Python的數(shù)據(jù)庫模塊有專門的數(shù)據(jù)庫模塊的規(guī)范,所以,其實不管使用哪種數(shù)據(jù)庫的方法都大同小異的,這里就給出一段示范的Python操作代碼:

#-*- encoding: gb2312 -*-  import os, sys, string  import MySQLdb   # 連接數(shù)據(jù)庫   try:      conn = MySQLdb.connect(host='localhost',user='root',passwd='xxxx',db='test1')  except Exception, e:      print e      sys.exit()   # 獲取cursor對象來進行操作   cursor = conn.cursor()  # 創(chuàng)建表  sql = "create table if not exists test1(name varchar(128) primary key, age int(4))" cursor.execute(sql)  # 插入數(shù)據(jù)  sql = "insert into test1(name, age) values ('%s', %d)" % ("zhaowei", 23)  try:      cursor.execute(sql)  except Exception, e:      print e   sql = "insert into test1(name, age) values ('%s', %d)" % ("張三", 21)  try:      cursor.execute(sql)  except Exception, e:      print e  # 插入多條   sql = "insert into test1(name, age) values (%s, %s)"   val = (("李四", 24), ("王五", 25), ("洪六", 26))  try:      cursor.executemany(sql, val)  except Exception, e:      print e   #查詢出數(shù)據(jù)  sql = "select * from test1" cursor.execute(sql)  alldata = cursor.fetchall()  # 如果有數(shù)據(jù)返回,就循環(huán)輸出, alldata是有個二維的列表  if alldata:      for rec in alldata:          print rec[0], rec[1]    cursor.close()   conn.close()

看完上述內(nèi)容,你們對如何進行對Python操作方法的說明有進一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。

網(wǎng)頁名稱:如何進行對Python操作方法的說明
本文URL:http://chinadenli.net/article18/gspggp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版ChatGPT全網(wǎng)營銷推廣企業(yè)網(wǎng)站制作小程序開發(fā)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁設(shè)計公司