async await了解一下 典型異步了
class TempDataFileCanIter(object):
"""
將文件對(duì)象封裝成迭代器
"""
def __init__(self, tempDataFilePath):
self.tDFile = open(tempDataFilePath, "r")
def __iter__(self):
return self
def next(self):
try:
for line in self.tDFile:
return line.rstrip()
raise StopIteration()
except StopIteration:
self.tDFile.close()
raise StopIteration()
except BaseException, ex:
self.tDFile.close()
raise Exception(ex)
***def __def__(self):
self.tDFile.close()***
自己在類中加了個(gè)析構(gòu)函數(shù)。所以只要在某個(gè)函數(shù)作用域中生成該類實(shí)例對(duì)象和使用,并且最后這個(gè)函數(shù)結(jié)束,那么對(duì)象的析構(gòu)函數(shù)就被調(diào)用就可以保證關(guān)閉文件(其他不會(huì)關(guān)閉的情況我也想不到了)。其實(shí)我一般都是用with的,就是項(xiàng)目比較特殊with不滿足。
感謝@yszou 的回答。
原文不就是這個(gè)字符嗎?
依錯(cuò)誤信息來看,這一行
image_file_path = value["path"]
有問題,因?yàn)?value 變量是 list 或 tuple。
add 'r' in front of address, like this (r'C:....')
我是直接編輯 /etc/paths,把 /usr/local/anaconda3/bin 加進(jìn)去。
看這個(gè):Get your anaconda ready with brew install
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.or
g', port=443): Read timed out. (read timeout=15)",)': /simple/mysqldb/
Could not find a version that satisfies the requirement MySQLdb (from versions
: )
pip --default-timeout=100 install MySQLdb
pip install --index https://mirrors.ustc.edu.cn/pypi/web/simple/ virtualenv load model 可能比較長吧
for i in open('score.txt', 'r'):
list1=i.split()
tuple1=tuple(list1)
print(tuple1)
open_tmp=open('score.txt', 'r')
key_tmp=open_tmp.readline()
key1=key_tmp.split()
stu_info = []
for i2 in open_tmp:
key2=i2.split()
zip_put=dict(zip(key1,key2))
stu_info.append(zip_put)
def three():
score = []
m_score = []
f_score = []
for dct in stu_info:
sco = dct['score']
score.append(sco)
if dct['sex'] == 'm':
sc_m = dct['score']
m_score.append(sc_m)
if dct['sex'] == 'f':
sc_f = dct['score']
f_score.append(sc_f)
# 最高分學(xué)生
for stu in stu_info:
if stu['score'] == max(score):
print(stu)
# 最低分學(xué)生
for stu in stu_info:
if stu['score'] == min(score):
print(stu)
def avg(score):
sum = 0
for i in score:
sum += int(i)
avg = sum/len(score)
return avg
# 平均分
print(avg(score))
print(avg(m_score))
print(avg(f_score))
three()
def four():
# 編輯
with open("score.txt","r",encoding="utf-8") as f:
lines = f.readlines()
with open("score.txt","w",encoding="utf-8") as f_w:
for line in lines:
if "舊內(nèi)容" in line:
line = line.replace("舊內(nèi)容", '新內(nèi)容')
f_w.write(line)
# 增加
with open("score.txt","r",encoding="utf-8") as f:
lines = f.readlines()
with open("score.txt","w",encoding="utf-8") as f_w:
f_w.write('新增內(nèi)容')
# 刪除信息
with open("score.txt","r",encoding="utf-8") as f:
lines = f.readlines()
with open("score.txt","w",encoding="utf-8") as f_w:
for line in lines:
if "你要?jiǎng)h的學(xué)生" in line:
continue
f_w.write(line)
four()
mysql可以使用 Spatial 空間數(shù)據(jù)類型, 里面有點(diǎn),線,面. 一個(gè)字段就能保存, 不需要建表.
requests.get是requests庫(第三方庫)的get請(qǐng)求, 參考http://docs.python-requests.o...
urllib2.Request是urllib2庫(官方庫)的請(qǐng)求,既可以是get也可以是post 參考https://docs.python.org/2.7/l...
這是js中作用域的問題跟vue沒關(guān)系,在學(xué)vue之前還是要好好的了解下js原理。建議去看看js權(quán)威指南。
python 2.7里print是語句:
print "hello world"
python 3.x里print是函數(shù):
print("hello world")from ..models import User 試試
老哥首先你的SID沒有問題 ,排查思路:
2.我是昨天研究的 ,你的pandas 學(xué)習(xí)了 pd.read_sql(sql,conn) 這個(gè)寫法待驗(yàn)證 ,是我get 到的點(diǎn)
3.我遇到的問題是在ubuntu用pycharm里寫代碼無法連接oracle數(shù)據(jù)庫 ,但pycharm 自帶的工具可以連接,在shell里也可以正常連接 最后也沒有找到原因 一直報(bào)錯(cuò)說是不是64位客戶端 ,但我所有的包都是64位的,待解決。。。
4.最后附上干貨,我的連接demo 以及將數(shù)據(jù)寫入到csv文件,僅供參考,老哥記得回復(fù)我,維護(hù)社區(qū)秩序。。
#!/usr/bin/python
import cx_Oracle as oracle
import csv
def oraclesql(cursor):
#fp = open('D:/1.sql')
#fp_sql = fp.read()
cursor.execute("select * from emp")
data = cursor.fetchall()
#print (list(data))
return list(data)
def write_to_csv(content):
with open('oracle.csv','a') as csvfile:
filename = ['empno','ename','job','mgr','hiredate','sal','comm','deptno']
#filename = ['LOTS','ORG_ID','YEAR_TIME','NAME_PATIENT','GENDER','BIRTHDAY','AGE','RESIDENT_ID','HUKOU_ADDRESS']
write = csv.writer(csvfile,delimiter=',')
# write.writeheader()
write.writerows([content])
if __name__ == '__main__':
ipaddr = "127.0.0.1"
username = "scott"
password = "scott"
oracle_port = "1521"
oracle_service = "orcl"
try:
db = oracle.connect(username+"/"+password+"@"+ipaddr+":"+oracle_port+"/"+oracle_service)
# 將異常捕捉
except Exception as e:
print(e)
else:
cursor = db.cursor()
data = oraclesql(cursor)
for i in data:
text = list(i)
#print(text)
write_to_csv(text)
cursor.close()
db.close()
ret.status_code == requests.codes.ok
http://www.python-requests.or...
你傳的url是https的就是https不可能是http,請(qǐng)求的端口都不一樣,http是80,https是443
ret.text是你獲取的內(nèi)容,如果內(nèi)容不是你想要的,需要傳入headers
command+shift+P進(jìn)Command Palette,輸入python: Select Interpreter,選擇你需要的環(huán)境。
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級(jí)產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。