日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

發布時間:2025/3/11 python 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中打印文件名,关闭状态和文件模式的全部內容,希望文章能夠幫你解決所遇到的問題。

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