新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:pyhon中File對(duì)象的屬性
一個(gè)文件被打開后,你有一個(gè)file對(duì)象,你可以得到有關(guān)該文件的各種信息。

創(chuàng)新互聯(lián)專注于淮濱企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè)公司,商城網(wǎng)站開發(fā)?;礊I網(wǎng)站建設(shè)公司,為淮濱等地區(qū)提供建站服務(wù)。全流程按需制作網(wǎng)站,專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
以下是和file對(duì)象相關(guān)的所有屬性的列表:
如下實(shí)例:
#!/usr/bin/python
# 打開一個(gè)文件
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
print "Closed or not : ", fo.closed
print "Opening mode : ", fo.mode
print "Softspace flag : ", fo.softspace
以上實(shí)例輸出結(jié)果:
Name of the file: foo.txt Closed or not : False Opening mode : wb Softspace flag : 0
Close()方法
File對(duì)象的close()方法刷新緩沖區(qū)里任何還沒寫入的信息,并關(guān)閉該文件,這之后便不能再進(jìn)行寫入。
當(dāng)一個(gè)文件對(duì)象的引用被重新指定給另一個(gè)文件時(shí),Python會(huì)關(guān)閉之前的文件。用close()方法關(guān)閉文件是一個(gè)很好的習(xí)慣。
語法:
fileObject.close();
例子:
#!/usr/bin/python
# 打開一個(gè)文件
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
# 關(guān)閉打開的文件
fo.close()
以上實(shí)例輸出結(jié)果:
Name of the file: foo.txt
標(biāo)題名稱:創(chuàng)新互聯(lián)Python教程:pyhon中File對(duì)象的屬性
當(dāng)前URL:http://www.dlmjj.cn/article/djchigc.html


咨詢
建站咨詢
