日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python 打印文件名_在Python中打印文件名,关闭状态和文件模式

發布時間:2025/3/11 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python 打印文件名_在Python中打印文件名,关闭状态和文件模式 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python 打印文件名

Prerequisite: Opening, closing a file/open(), close() functions in Python

先決條件: 在Python中打開,關閉文件/ open(),close()函數

1)文件名(file_object.name) (1) File name (file_object.name))

To get the file name, we use file_object.name – it returns the opened file name with extension.

要獲取文件名,我們使用file_object.name-它返回帶有擴展名的打開的文件名。

2)文件關閉狀態(file_object.closed) (2) File Close status (file_object.closed))

To find the file close status i.e. to check whether a file is opened or closed, we use file_object.close. It returns "True", if the file is opened otherwise it returns "False".

為了找到文件關閉狀態,即檢查文件是打開還是關閉,我們使用file_object.close 。 如果打開文件,則返回“ True” ,否則返回“ False” 。

3)文件模式(file_object.mode) (3) File Mode (file_object.mode))

To find the current file opening mode in which the file is opened, we use file_object.mode. It returns file opening mode like "wt", "rt" etc, which we have discussed in the previous post (Opening, closing a file/open(), close() functions in Python).

為了找到打開文件的當前文件打開模式,我們使用file_object.mode 。 它返回文件打開模式,如“ wt” , “ rt”等,我們在上一篇文章中已經討論過( 在Python中打開,關閉文件/ open(),close()函數 )。

Example:

例:

# opening a file in write mode fo = open("data.txt","wt")# printing name of the file print("Name of the File : ",fo.name) # priting file closed status print("Closed or Not : ",fo.closed) # printing file Opening mode print("Opening Mode : ",fo.mode)# closing the file fo.close()print("")# priting file closed status after closing the file print("Closed or Not : ",fo.closed)

Output

輸出量

Name of the File : data.txt Closed or Not : False Opening Mode : wtClosed or Not : True

翻譯自: https://www.includehelp.com/python/printing-file-name-closed-status-and-file-mode.aspx

python 打印文件名

總結

以上是生活随笔為你收集整理的python 打印文件名_在Python中打印文件名,关闭状态和文件模式的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。