本文實(shí)例講述了python打開(kāi)文件并獲取文件相關(guān)屬性的方法。分享給大家供大家參考。具體分析如下:
下面的代碼通過(guò)open函數(shù)打開(kāi)文件,并輸出文件名、打開(kāi)狀態(tài)、打開(kāi)模式等屬性
#!/usr/bin/python# Open a filefo = open("foo.txt", "wb")print "Name of the file: ", fo.nameprint "Closed or not : ", fo.closedprint "Opening mode : ", fo.modeprint "Softspace flag : ", fo.softspace
輸出結(jié)果:
Name of the file: foo.txtClosed or not : FalseOpening mode : wbSoftspace flag : 0
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
新聞熱點(diǎn)
疑難解答
圖片精選