本文實例講述了python打開文件并獲取文件相關(guān)屬性的方法。分享給大家供大家參考。具體分析如下:
下面的代碼通過open函數(shù)打開文件,并輸出文件名、打開狀態(tà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
希望本文所述對大家的Python程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選