基於py3和pymysql查詢某時間段的資料

2022-03-12 21:17:37 字數 661 閱讀 7964

#

python3

#xiaodeng

#基於py3和pymysql查詢某時間段的資料

import

pymysql

conn=pymysql.connect(user='

root

',passwd='

root

',host='

localhost

',db='

test.db')

cur=conn.cursor()

'''【核心語句】

'''cur.execute(

"select grage from 表名 where 時間字段 between '開始時間' and '結束時間'")

#eg:

#select grage from 表名 where 時間字段 between '2010-7-12 11:18:54' and '2010-7-12 11:22:20'

#用data接收需要返回的資料

data=cur.fethall()

#資料提取工作

for name,age in

data:

print

(name,age)

conn.close()

cur.close()

py2和py3之間的區別

1.編碼 py2採用的是ascll編碼 py3採用unicode編碼 2.print py2中print是乙個關鍵字 py3中print是乙個函式,含有括號 3.input py2中raw input 這個函式返回乙個字串,但不會對輸入的字串進行計算 比如將它轉化成int或者float input ...

py2和py3之間的不同

很瑣碎,而print語法的變化可能是最廣為人知的了,但是仍值得一提的是 python 2 的 print 宣告已經被print 函式取代了,這意味著我們必須包裝我們想列印在小括號中的物件。python 2 不具有額外的小括號問題。但對比一下,如果我們按照 python 2 的方式不使用小括號呼叫pr...

Py3 翻譯問題 replace

powered by ab in 局外人 乙個翻譯的水題,用套版就行了。while true try n int input s input import string as st before st.ascii lowercase 返回乙個字串全是小寫 after before n before ...