Python语言基础 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

File对象的属性


一个文件被打开后,你有一个file对象,你可以得到有关该文件的各种信息。以下是和file对象相关的所有属性的列表:

属性描述
file.closed返回true如果文件已被关闭,否则返回false。
file.mode返回被打开文件的访问模式。
file.name返回文件的名称。
file.softspace如果用print输出后,必须跟一个空格符,则返回false。否则返回true。
# 打开一个文件
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
print "Closed or not : ", fo.closed
print "Opening mode : ", fo.mode
print "Softspace flag : ", fo.softspace