㈠ python pycurl有哪些參數
#!/usr/bin/env python2
#encoding=utf8
import pycurl
import StringIO
# 安裝pycurl到http://pycurl.sourceforge.net/這里去找.
# 在windows安裝的話http://pycurl.sourceforge.net/download/ , 看你使用的版本決定下載那個,我在 windows使用的是python2.4, 所以下載 pycurl-ssl-7.15.5.1.win32-py2.4.exe 。
def test(debug_type, debug_msg):
print "debug(%d): %s" % (debug_type, debug_msg)
def postFile(url,post_file):
#print pycurl.version_info()
#這個函數創建一個同 libcurl中的CURL處理器相對應的Curl對象.Curl對象自動的設置CURLOPT_VERBOSE為0, CURLOPT_NOPROGRESS為1,提供一個默認的CURLOPT_USERAGENT和設置CURLOPT_ERRORBUFFER指向一個私有的錯誤緩沖區.
c = pycurl.Curl() #創建一個同libcurl中的CURL處理器相對應的Curl對象
b = StringIO.StringIO()
#c.setopt(c.POST, 1)
c.setopt(pycurl.URL, url) #設置要訪問的網址 url = "http://www.cnn.com"
#寫的回調
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1) #參數有1、2
#最大重定向次數,可以預防重定向陷阱
c.setopt(pycurl.MAXREDIRS, 5)
#連接超時設置
c.setopt(pycurl.CONNECTTIMEOUT, 60) #鏈接超時
# c.setopt(pycurl.TIMEOUT, 300) #下載超時
# c.setopt(pycurl.HEADER, True)
# c.setopt(c.HTTPHEADER, ["Content-Type: application/x-www-form-urlencoded","X-Requested-With:XMLHttpRequest","Cookie:"+set_cookie[0]])
#模擬瀏覽器
c.setopt(pycurl.USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)")
# c.setopt(pycurl.AUTOREFERER,1)
# c.setopt(c.REFERER, url)
# cookie設置
# Option -b/--cookie <name=string/file> Cookie string or file to read cookies from
# Note: must be a string, not a file object.
# c.setopt(pycurl.COOKIEFILE, "cookie_file_name")
# Option -c/--cookie-jar Write cookies to this file after operation
# Note: must be a string, not a file object.
# c.setopt(pycurl.COOKIEJAR, "cookie_file_name")
# Option -d/--data HTTP POST data
post_data_dic = {"name":"value"}
c.setopt(c.POSTFIELDS, urllib.urlencode(post_data_dic))
#設置代理
# c.setopt(pycurl.PROXY, 『http://11.11.11.11:8080′)
# c.setopt(pycurl.PROXYUSERPWD, 『aaa:aaa』)
#不明確作用
# c.setopt(pycurl.HTTPPROXYTUNNEL,1) #隧道代理
# c.setopt(pycurl.NOSIGNAL, 1)
#設置post請求, 上傳文件的欄位名 上傳的文件
#post_file = "/home/ubuntu/avatar.jpg"
c.setopt(c.HTTPPOST, [("textname", (c.FORM_FILE, post_file))])
# 調試回調.調試信息類型是一個調試信 息的整數標示類型.在這個回調被調用時VERBOSE選項必須可用
# c.setopt(c.VERBOSE, 1) #verbose 詳細
# c.setopt(c.DEBUGFUNCTION, test)
# f = open("body", "wb")
# c.setopt(c.WRITEDATA, f)
# h = open("header", "wb")
# c.setopt(c.WRITEHEADER, h)
# print "Header is in file 'header', body is in file 'body'"
# f.close()
# h.close()
# c.setopt(c.NOPROGRESS, 0)
# c.setopt(c.PROGRESSFUNCTION, progress)
# c.setopt(c.OPT_FILETIME, 1)
#訪問,阻塞到訪問結束
c.perform() #執行上述訪問網址的操作
print "HTTP-code:", c.getinfo(c.HTTP_CODE) #列印出 200(HTTP狀態碼)
print "Total-time:", c.getinfo(c.TOTAL_TIME)
print "Download speed: %.2f bytes/second" % c.getinfo(c.SPEED_DOWNLOAD)
print "Document size: %d bytes" % c.getinfo(c.SIZE_DOWNLOAD)
print "Effective URL:", c.getinfo(c.EFFECTIVE_URL)
print "Content-type:", c.getinfo(c.CONTENT_TYPE)
print "Namelookup-time:", c.getinfo(c.NAMELOOKUP_TIME)
print "Redirect-time:", c.getinfo(c.REDIRECT_TIME)
print "Redirect-count:", c.getinfo(c.REDIRECT_COUNT)
# epoch = c.getinfo(c.INFO_FILETIME)
#print "Filetime: %d (%s)" % (epoch, time.ctime(epoch))
html = b.getvalue()
print(html)
b.close()
c.close()
㈡ 用python編寫的一個學生成績管理系統
# -*- coding: cp936 -*-
class StuInfo:
def __init__(self):
self.Stu=[{"Sno":"1","Sname":"姓名","ChineseScore":64,"MathsScore":34,"EnglishScore":94,"ComputerScore":83},
{"Sno":"2","Sname":"姓名","ChineseScore":44,"MathsScore":24,"EnglishScore":44,"ComputerScore":71},
{"Sno":"3","Sname":"姓名","ChineseScore":74,"MathsScore":35,"EnglishScore":74,"ComputerScore":93},
{"Sno":"4","Sname":"姓名","ChineseScore":94,"MathsScore":54,"EnglishScore":24,"ComputerScore":73}]
self.attribute={"Sno":"學號",
"Sname":"姓名",
"ChineseScore":"語文成績",
"MathsScore":"數學成績",
"EnglishScore":"英語成績",
"ComputerScore":"計算機成績"
}
def _add(self):
'''添加'''
singleInfo={}
for i in self.attribute:
if "Score" in i:
singleInfo[i]=int(raw_input(self.attribute[i]+"\n"))
else:
singleInfo[i]=raw_input(self.attribute[i]+"\n").strip()
self.Stu.append(singleInfo)
print "添加成功OK"
for i in singleInfo:
print i,"=",singleInfo[i]
def _del(self):
"""刪除學號為Sno的記錄"""
Sno=raw_input("學號:\n")
self.Stu.remove(self.__getInfo(Sno))
print "刪除成功OK"
def _update(self):
"""更新數據"""
Sno=raw_input("學號\n").strip()
prefix="修改"
updateOperate={"1":"ChineseScore",
"2":"MathsScore",
"3":"EnglishScore",
"4":"ComputerScore"}
for i in updateOperate:
print i,"-->",prefix+self.attribute[updateOperate[i]]
getOperateNum=raw_input("選擇操作:\n")
if getOperateNum:
getNewValue=int(raw_input("輸入新的值:\n"))
record=self.__getInfo(Sno)
record[updateOperate[getOperateNum]]=getNewValue
print "修改"+record["Sname"]+"的"+str(updateOperate[getOperateNum])+"成績=",getNewValue,"\n成功OK"
def _getInfo(self):
"""查詢數據"""
while True:
print "1->學號查詢 2->條件查詢 3->退出"
getNum=raw_input("選擇:\n")
if getNum=="1":
Sno=raw_input("學號:\n")
print filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
elif getNum=="2":
print "ChineseScore 語文成績;","MathsScore 數學成績;","EnglishScore 英語成績;","ComputerScore 計算機成績;"
print "等於 ==,小於 <, 大於 > ,大於等於 >=,小於等於<= ,不等於!="
print "按如下格式輸入查詢條件 eg: ChineseScore>=60 "
expr=raw_input("條件:\n")
Infos=self.__getInfo(expr=expr)
if Infos:
print "共%d記錄"%len(Infos)
for i in Infos:
print i
else:
print "記錄為空"
elif getNum=="3":
break
else:
pass
def __getInfo(self,Sno=None,expr=""):
"""查詢數據
根據學號 _getInfo("111111")
根據分數 _getInfo("EnglishSorce>80")"""
if Sno:
return filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
for operate in [">=",">","<=","<","==","!="]:
if operate in expr:
gradeName,value=expr.split(operate)
return filter(lambda record: eval( repr(record[gradeName.strip()])+operate+value.strip()) ,self.Stu)
return {}
def _showAll(self):
"""顯示所有記錄"""
for i in self.Stu:
print i
@staticmethod
def test():
"""測試"""
_StuInfo=StuInfo()
while True:
print "1->錄入數據 2->修改數據 3->刪除數據 4->查詢數據 5->查看數據 6->退出"
t=raw_input("選擇:\n")
if t=="1":
print "錄入數據"
_StuInfo._add()
elif t=="2":
print "修改數據"
_StuInfo._update()
elif t=="3":
print "刪除數據"
_StuInfo._del()
elif t=="4":
print "查詢數據"
_StuInfo._getInfo()
elif t=="5":
print "顯示所有記錄"
_StuInfo._showAll()
elif t=="6":
break
else:
pass
if __name__=="__main__":
StuInfo.test()
㈢ 用Python編寫班級檔案管理系統
# -*- coding: cp936 -*-
class StuInfo:
def __init__(self):
self.Stu=[{"Sno":"1","Sname":"姓名","ChineseScore":64,"MathsScore":34,"EnglishScore":94,"ComputerScore":83},
{"Sno":"2","Sname":"姓名","ChineseScore":44,"MathsScore":24,"EnglishScore":44,"ComputerScore":71},
{"Sno":"3","Sname":"姓名","ChineseScore":74,"MathsScore":35,"EnglishScore":74,"ComputerScore":93},
{"Sno":"4","Sname":"姓名","ChineseScore":94,"MathsScore":54,"EnglishScore":24,"ComputerScore":73}]
self.attribute={"Sno":"學號",
"Sname":"姓名",
"ChineseScore":"語文成績",
"MathsScore":"數學成績",
"EnglishScore":"英語成績",
"ComputerScore":"計算機成績"
}
def _add(self):
'''添加'''
singleInfo={}
for i in self.attribute:
if "Score" in i:
singleInfo[i]=int(raw_input(self.attribute[i]+"\n"))
else:
singleInfo[i]=raw_input(self.attribute[i]+"\n").strip()
self.Stu.append(singleInfo)
print "添加成功OK"
for i in singleInfo:
print i,"=",singleInfo[i]
def _del(self):
"""刪除學號為Sno的記錄"""
Sno=raw_input("學號:\n")
self.Stu.remove(self.__getInfo(Sno))
print "刪除成功OK"
def _update(self):
"""更新數據"""
Sno=raw_input("學號\n").strip()
prefix="修改"
updateOperate={"1":"ChineseScore",
"2":"MathsScore",
"3":"EnglishScore",
"4":"ComputerScore"}
for i in updateOperate:
print i,"-->",prefix+self.attribute[updateOperate[i]]
getOperateNum=raw_input("選擇操作:\n")
if getOperateNum:
getNewValue=int(raw_input("輸入新的值:\n"))
record=self.__getInfo(Sno)
record[updateOperate[getOperateNum]]=getNewValue
print "修改"+record["Sname"]+"的"+str(updateOperate[getOperateNum])+"成績=",getNewValue,"\n成功OK"
def _getInfo(self):
"""查詢數據"""
while True:
print "1->學號查詢 2->條件查詢 3->退出"
getNum=raw_input("選擇:\n")
if getNum=="1":
Sno=raw_input("學號:\n")
print filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
elif getNum=="2":
print "ChineseScore 語文成績;","MathsScore 數學成績;","EnglishScore 英語成績;","ComputerScore 計算機成績;"
print "等於 ==,小於 <, 大於 > ,大於等於 >=,小於等於<= ,不等於!="
print "按如下格式輸入查詢條件 eg: ChineseScore>=60 "
expr=raw_input("條件:\n")
笭工蒂繼酈荒墊維叮哩 Infos=self.__getInfo(expr=expr)
if Infos:
print "共%d記錄"%len(Infos)
for i in Infos:
print i
else:
print "記錄為空"
elif getNum=="3":
break
else:
pass
def __getInfo(self,Sno=None,expr=""):
"""查詢數據
根據學號 _getInfo("111111")
根據分數 _getInfo("EnglishSorce>80")"""
if Sno:
return filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
for operate in [">=",">","<=","<","==","!="]:
if operate in expr:
gradeName,value=expr.split(operate)
return filter(lambda record: eval( repr(record[gradeName.strip()])+operate+value.strip()) ,self.Stu)
return {}
def _showAll(self):
"""顯示所有記錄"""
for i in self.Stu:
print i
@staticmethod
def test():
"""測試"""
_StuInfo=StuInfo()
while True:
print "1->錄入數據 2->修改數據 3->刪除數據 4->查詢數據 5->查看數據 6->退出"
t=raw_input("選擇:\n")
if t=="1":
print "錄入數據"
_StuInfo._add()
elif t=="2":
print "修改數據"
_StuInfo._update()
elif t=="3":
print "刪除數據"
_StuInfo._del()
elif t=="4":
print "查詢數據"
_StuInfo._getInfo()
elif t=="5":
print "顯示所有記錄"
_StuInfo._showAll()
elif t=="6":
break
else:
pass
if __name__=="__main__":
StuInfo.test()
㈣ python 字元串處理 SQL查詢語句
>>> base = """("%(k)s" = '%(v)s')"""
>>> print ' and '.join([base % dict(k=k, v=v) for k,v in dict(name='tim', email='[email protected]').items()])
("email" = '[email protected]') and ("name" = 'tim')
>>>
另外: 強烈建議不採用拼接字元串的方式定義SQL,而是採用參數
㈤ 遙感數字圖像定量反演的方法
遙感數字圖像可以用Google earth engine python API來實現定量反演。
用基於GEE的pythonAPI,主要實現以下內容:
站點數據和遙感影像匹配。
利用機器學習/深度學習模型進行匹配數據的訓練。
將訓練的模型用於GEE上的影像數據,實現參數反演結果成圖。
提取影像的metedata,作為模型的輸入數據。
注意,直接採用img.get( )得到的是computerobject這種類型的結果,無法在機器學習模型中輸入和計算,應加上.getInfo()。
總結如下:
反演,在人工智慧領域又稱為人工智慧反演(inversion with artificial intelligence),是指能夠模仿人類智能的計算機程序系統即人工智慧專家系統,它具有學習和推理的功能。例如模擬退火最優化系統、人工神經網路系統等。
在反問題求解過程中應用人工智慧的方法技術,引導局部或全局尋優,這種反演方法稱為人工智慧反演技術。
㈥ python順序表
本問題回答如下:你可以根據自己的需求稍微改動一下
# -*- coding: cp936 -*-
class StuInfo:
def __init__(self):
self.Stu=[{"Sno":"1","Sname":"姓名","ChineseScore":64,"MathsScore":34,"EnglishScore":94,"ComputerScore":83},
{"Sno":"2","Sname":"姓名","ChineseScore":44,"MathsScore":24,"EnglishScore":44,"ComputerScore":71},
{"Sno":"3","Sname":"姓名","ChineseScore":74,"MathsScore":35,"EnglishScore":74,"ComputerScore":93},
{"Sno":"4","Sname":"姓名","ChineseScore":94,"MathsScore":54,"EnglishScore":24,"ComputerScore":73}]
self.attribute={"Sno":"學號",
"Sname":"姓名",
"ChineseScore":"語文成績",
"MathsScore":"數學成績",
"EnglishScore":"英語成績",
"ComputerScore":"計算機成績"
}
def _add(self):
'''添加'''
singleInfo={}
for i in self.attribute:
if "Score" in i:
singleInfo[i]=int(raw_input(self.attribute[i]+"\n"))
else:
singleInfo[i]=raw_input(self.attribute[i]+"\n").strip()
self.Stu.append(singleInfo)
print "添加成功OK"
for i in singleInfo:
print i,"=",singleInfo[i]
def _del(self):
"""刪除學號為Sno的記錄"""
Sno=raw_input("學號:\n")
self.Stu.remove(self.__getInfo(Sno))
print "刪除成功OK"
def _update(self):
"""更新數據"""
Sno=raw_input("學號\n").strip()
prefix="修改"
updateOperate={"1":"ChineseScore",
"2":"MathsScore",
"3":"EnglishScore",
"4":"ComputerScore"}
for i in updateOperate:
print i,"-->",prefix+self.attribute[updateOperate[i]]
getOperateNum=raw_input("選擇操作:\n")
if getOperateNum:
getNewValue=int(raw_input("輸入新的值:\n"))
record=self.__getInfo(Sno)
record[updateOperate[getOperateNum]]=getNewValue
print "修改"+record["Sname"]+"的"+str(updateOperate[getOperateNum])+"成績=",getNewValue,"\n成功OK"
def _getInfo(self):
"""查詢數據"""
while True:
print "1->學號查詢 2->條件查詢 3->退出"
getNum=raw_input("選擇:\n")
if getNum=="1":
Sno=raw_input("學號:\n")
print filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
elif getNum=="2":
print "ChineseScore 語文成績;","MathsScore 數學成績;","EnglishScore 英語成績;","ComputerScore 計算機成績;"
print "等於 ==,小於 <, 大於 > ,大於等於 >=,小於等於<= ,不等於!="
print "按如下格式輸入查詢條件 eg: ChineseScore>=60 "
expr=raw_input("條件:\n")
Infos=self.__getInfo(expr=expr)
if Infos:
print "共%d記錄"%len(Infos)
for i in Infos:
print i
else:
print "記錄為空"
elif getNum=="3":
break
else:
pass
def __getInfo(self,Sno=None,expr=""):
"""查詢數據
根據學號 _getInfo("111111")
根據分數 _getInfo("EnglishSorce>80")"""
if Sno:
return filter(lambda record:record["Sno"]==Sno,self.Stu)[0]
for operate in [">=",">","<=","<","==","!="]:
if operate in expr:
gradeName,value=expr.split(operate)
return filter(lambda record: eval( repr(record[gradeName.strip()])+operate+value.strip()) ,self.Stu)
return {}
def _showAll(self):
"""顯示所有記錄"""
for i in self.Stu:
print i
@staticmethod
def test():
"""測試"""
_StuInfo=StuInfo()
while True:
print "1->錄入數據 2->修改數據 3->刪除數據 4->查詢數據 5->查看數據 6->退出"
t=raw_input("選擇:\n")
if t=="1":
print "錄入數據"
_StuInfo._add()
elif t=="2":
print "修改數據"
_StuInfo._update()
elif t=="3":
print "刪除數據"
_StuInfo._del()
elif t=="4":
print "查詢數據"
_StuInfo._getInfo()
elif t=="5":
print "顯示所有記錄"
_StuInfo._showAll()
elif t=="6":
break
else:
pass
if __name__=="__main__":
StuInfo.test()
希望本次回答對你的提問有所幫助謝謝
㈦ python如何實現多行數字自增
#!/usr/bin/envpython
#coding:utf-8
defgetinfo(num):
i=1
str_num="1"
for_inrange(num):
str_num+='0'
foriinrange(1,int(str_num)):
for_inrange(num):
print"test%s"%str(i).zfill(num)
getinfo(3)