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

yipeiwu_com6年前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程序设计有所帮助。

相关文章

对Pandas DataFrame缺失值的查找与填充示例讲解

查看DataFrame中每一列是否存在空值: temp = data.isnull().any() #列中是否存在空值 print(type(temp)) print(temp)...

PyTorch读取Cifar数据集并显示图片的实例讲解

PyTorch读取Cifar数据集并显示图片的实例讲解

首先了解一下需要的几个类所在的package from torchvision import transforms, datasets as ds from torch.utils...

Python 使用type来定义类的实现

Python 使用type来定义类的实现

我们先来看一张图 仔细观察: 我们使用 class 定义了 Class类,然后实例化给 cls 观察cls的类型,它的类型指向 Class 那么Class的类型指向谁呢?指向type...

基于django传递数据到后端的例子

最近遇到一个问题,前端表单我写了多个按钮,每个按钮通过for循环来给name赋值如下: <input type="button" class="btn btn-info btn...

Python:slice与indices的用法

slice:   eg:     >>>e=[0,1,2,3,4,5,6]     >>>s=slice(2,3)     >>&...