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     :  wt
Closed or Not    :  True

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

python 打印文件名

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

  1. python调用everything批量查找表格中的文件名在磁盘中是否存在

    python调用everything批量查找表格中的文件名在磁盘中是否存在 介绍 Everything 配置 使用openpyxl读写文件 读文件 写文件 BeautifulSoup的使用 创建 be ...

  2. python 时间序列预测_使用Python进行动手时间序列预测

    python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...

  3. python 概率分布模型_使用python的概率模型进行公司估值

    python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...

  4. linux 获取文件名函数,Linux shell中提取文件名和路径

    前言 有个软件叫HLAreporter,它真的搞人,基本上就是shell脚本联合起来的,关键是居然还有各种小问题,其中之一就是关于文件名和目录名这个,导致程序只能在软件本身的目录运行,然后各种bug, ...

  5. python打印时间_在Python中定义Main函数(第二部分)

    Main函数的最佳实践 既然您已经了解两种执行方式上的差异,那么掌握一些最佳实践方案还是很有用的.它们将适用于编写作为脚本运行的代码或者在另一个模块导入的代码. 如下是四种实践方式: 将大部分代码放入 ...

  6. python 打印类型_让Python输出更漂亮:PrettyPrinter

    PrettyPrinter是Python 3.6 及以上版本中的一个功能强大.支持语法高亮.描述性的美化打印包.它使用了改进的Wadler-Leijen布局算法,和Haskell打印美化库中的pret ...

  7. python符号计算 漂亮地打印出来_让Python输出更漂亮:PrettyPrinter

    PrettyPrinter是Python 3.6 及以上版本中的一个功能强大.支持语法高亮.描述性的美化打印包.它使用了改进的Wadler-Leijen布局算法,和Haskell打印美化库中的pret ...

  8. 如何用python打印田字格_如何用 3D 打印一双顶级跑鞋回形针

    马拉松赛场上的跑鞋五光十色,除了美观之外,它们还有一个重要作用:保护运动员不受伤害. 跑步时,从脚碰到地面开始会受到地面的反作用力.从着陆的减速到随着脚步推蹬过程的加速,这一过程中脚和地面的压力会达到 ...

  9. python获取股指_用Python读取csv文件中的沪深300指数历史交易数据

    保存路径:D:\python\用Python读取csv文件中的沪深300指数历史交易数据 程序名称:readcsvhs300.py: 数据名称:沪深300指数历史交易数据.csv: 开发环境:Win7 ...

最新文章

  1. 刀片服务器提升三要点
  2. HDU 4405 概率期望DP
  3. 图像处理中ct图的通道是多少_常见医疗扫描图像处理步骤
  4. [Python学习记录]——Hello Python
  5. 腾讯V265编码器:给用户以完备的265体验
  6. Oracle入门(五A)之conn命令
  7. java ajax jquery分页插件_jquery ajax分页插件的简单实现
  8. 中国十大科技进展2项,世界十大科技进展6项生物相关;相比工程,生物与国际差距还是较大...
  9. 百度Q2扭亏为盈 李彦宏发信勉励:变革带来阵痛 但能走得更稳更远
  10. 使用java语言操作,如何来实现MySQL中Blob字段的存取
  11. 正倒向随机微分方程(FBSDE)解对初始值的依赖性
  12. 橡胶支座抗压弹性模量计算公式_橡胶支座计算
  13. css的after右箭头,偷师成功,纯CSS绘制右箭头及其他——灵动外卖开发笔记
  14. 手机号归属地能改吗?支付及通讯行业怎么看?
  15. tiup telemetry
  16. 根据原厂uboot进行移植
  17. python中sklearn实现决策树及模型评估_sklearn实现决策树
  18. c++: internal compiler error: 已杀死 (program cc1plus)的解决方法
  19. js中关于字符串操作的命令
  20. python简单实现经典的图像匹配算法SIFT

热门文章

  1. matlab中如何调用gpu进行并行计算_极致安卓-Termux/Aid learning开启WebGL手机GPU并行计算...
  2. 如何查询linux服务器的网卡,Linux服务器如何查看有没有无线网卡
  3. 传统的6d位姿估计fangfa1_李飞飞团队最新论文:基于anchor关键点的类别级物体6D位姿跟踪...
  4. php养老院管理系统,XYCMS养老院建站系统 v3.8
  5. 获取zabbix监控数据
  6. 13 张图带你学懂 Kubernetes Service(转载)
  7. 求二叉树节点个数、叶子节点、节点层次与宽度
  8. 委托BegionInvoke和窗体BegionInvoke
  9. 《C#多线程编程实战(原书第2版)》——3.2 在线程池中调用委托
  10. [J2ME]RSSOwlMidlet(RSS无线阅读器)设计说明