py: After opening the file, you can do things

File object properties
after a file is opened, you have a file object, you can get various information about the file.

The following is a list of all the properties and file objects related to:

Property description
file.closed returns true if the file has been closed, otherwise false.
file.mode return to the open file access patterns.
file.name returns the name of the file.
If the print output file.softspace used, must be followed by a space character, returns false. Otherwise, it returns true.
Following examples:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
# 打开一个文件
fo = open("foo.txt", "w")
print "文件名: ", fo.name
print "是否已关闭 : ", fo.closed
print "访问模式 : ", fo.mode
print "末尾是否强制加空格 : ", fo.softspace
Published 216 original articles · won praise 33 · views 90000 +

Guess you like

Origin blog.csdn.net/paulkg12/article/details/104816986