python检测是文件还是目录的方法

yipeiwu_com5年前Python基础

本文实例讲述了python检测是文件还是目录的方法。分享给大家供大家参考。具体实现方法如下:

import os
if os.path.isdir(path):
  print "it's a directory"
elif os.path.isfile(path):
  print "it's a normal file"
else:
  print "it's a special file (socket, FIFO, device file)"

希望本文所述对大家的Python程序设计有所帮助。

相关文章

详解python eval函数的妙用

python eval函数功能:将字符串str当成有效的表达式来求值并返回计算结果。 函数定义: eval(expression, globals=None, locals=Non...

pygame实现俄罗斯方块游戏(AI篇1)

pygame实现俄罗斯方块游戏(AI篇1)

上次更新到pygame实现俄罗斯方块游戏(基础篇3) 现在继续 一、定义玩家类 定义玩家类是为了便于进行手动和机器模式或各种不同机器人模式的混合使用,增加代码扩展性。 可以先定义一个玩家...

在VS Code上搭建Python开发环境的方法

在VS Code上搭建Python开发环境的方法

1、下载安装 python https://www.python.org/downloads/windows/ web-based installer 在线安装 executable...

python字符串过滤性能比较5种方法

python字符串过滤性能比较5种方法比较 总共比较5种方法。直接看代码: import random import time import os import string ba...

python使用内存zipfile对象在内存中打包文件示例

复制代码 代码如下:import zipfileimport StringIO class InMemoryZip(object):    def __in...