【问题标题】:Get system file type names python [duplicate]获取系统文件类型名称python [重复]
【发布时间】:2018-11-12 11:13:17
【问题描述】:

有没有办法在 Python 中使用 OS 模块检索文件类型名称?

一个组成命令的例子:

>>> os.file_type('txt')

会返回:

'Text Document'

任何帮助将不胜感激:)

奥斯卡。

【问题讨论】:

标签: python python-3.x python-os


【解决方案1】:

要获取文件类型,您需要检查文件的扩展名

我认为这会有所帮助。

import os

if os.path.splitext(file)[1] == ".txt":
    pritn 'Text Document'

对于与操作系统相关的任务,您可以查看此文档。

https://github.com/Projesh07/Python-basic/blob/master/python_os_module/python_os_module.py

【讨论】:

    猜你喜欢
    • 2017-06-15
    • 2021-11-07
    • 1970-01-01
    • 2014-03-29
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    相关资源
    最近更新 更多