python检查指定文件是否存在的方法

yipeiwu_com5年前Python基础

本文实例讲述了python检查指定文件是否存在的方法。分享给大家供大家参考。具体如下:

import os
def file_exists(file_name): 
  if os.path.exists(file):
    return '%s is found' % file_name
  else: 
    return '%s is missing' % file_name

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

相关文章

使用python获取电脑的磁盘信息方法

使用Python获取电脑的磁盘信息需要借助于第三方的模块psutil,这个模块需要自己安装,纯粹的CPython下面不具备这个功能。 在iPython交互界面中进行如下演示: 查看电脑的...

python生成器与迭代器详解

列表生成式: 例一: a = [i+1 for i in range(10)] print(a) 输出: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] 例二...

Python实现删除Android工程中的冗余字符串

Android提供了一套很方便的进行资源(语言)国际化机制,为了更好地支持多语言,很多工程的翻译往往会放到类似crowdin这样的平台上。资源是全了,但是还是会有一些问题。 哪些问题 以...

对python中assert、isinstance的用法详解

1. assert 函数说明: Assert statements are a convenient way to insert debugging assertions into a...

python字符串格式化方式解析

1.%格式符 name = '李四' age = 18 a = "姓名:%s,年龄:%s"%(name,age) print(a) #姓名:李四,年龄:18 ​ b...