方法一:

 # -*- coding:utf-8 -*-
import os
import sys
from uiautomator import device as d filepath = r'E:\Project\A3A_8_4G\exercise\app_list\hello.apk' if os.path.isfile(filepath):
print "true"
else:
print "false"

总结:如果变量filepath中给出的是一个绝对路径的话,那么在使用os.path.isfile()时就只需要将这个绝对路径对应的变量传进来就行

方法二:

 # -*- coding:utf-8 -*-
import os
import sys
from uiautomator import device as d filepath = sys.path[0] + "\\app_list\\"
filename = "hello.apk" if os.path.isfile(os.path.join(filepath,filename)):
print "true"
else:
print "false"

总结:如果将路径和文件分开来写的话,那么在使用os.path.isfile()时,则必须将这两个连接起来使用,使用os.path.join()方法将路径和文件连接起来

方法三:

 # -*- coding:utf-8 -*-
import os
import sys
from uiautomator import device as d if os.path.isfile('E:\\Project\\A3A_8_4G\\exercise\\app_list\\hello.apk'):
print "true"
else:
print "false"

总结:这个就是直接在os.path.isfile()中传入绝对路径,但需要注意的是需要将\号进行转义,不然也会报错了

【Python】os.path.isfile()的使用方法汇总的更多相关文章

  1. python os.path.isfile函数

    最近刚开始学习Python,做了个小练习:扫描当前目录及其子目录中的文件,找出文件名中含有指定关键字的文件并打印文件名.思路很简单,如果是文件则判断是否满足条件:如果是目录则进入目录搜索文件,递归. ...

  2. python中由于中文路径引起的os.path.isfile(imgpath) == False问题

    昨天在用python脚本处理文件的时候,遇到了题述问题,明明文件时存在的,但是在用os.path.isfile(imgpath) == False进行判断的时候总是成立,在一开始以为是正反斜杠wind ...

  3. [python] os.path模块常用方法汇总

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  4. python os.path模块--转载

    os.path.abspath(path) #返回绝对路径 os.path.basename(path) #返回文件名 os.path.commonprefix(list) #返回list(多个路径) ...

  5. [转载]python os.path模块

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...

  6. python:os.path模块常用方法

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...

  7. python os.path模块常用方法详解

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...

  8. python os.path模块常用方法详解(转)

    转自:https://www.cnblogs.com/wuxie1989/p/5623435.html os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方 ...

  9. python os.path模块常用方法详解 ZZ

    os.path模块主要用于文件的属性获取,在编程中经常用到,以下是该模块的几种常用方法.更多的方法可以去查看官方文档:http://docs.python.org/library/os.path.ht ...

随机推荐

  1. UIKit 框架之UIView一

    - (id)initWithFrame:(CGRect)aRect //通过一个矩形对象初始化 Configuring a View’s Visual Appearance //配置视觉展示 @pro ...

  2. 在Java8的foreach()中不能break,如果需要continue时,可以使用return

    今天使用lambda表达式处理集合时,发现对return.break以及continue的使用有点迷惑,于是自己动手测试了一下,才发现在使用foreach()处理集合时不能使用break和contin ...

  3. [转]Webpack 入门教程

    本文转自:http://www.runoob.com/w3cnote/webpack-tutorial.html Webpack 是一个前端资源加载/打包工具.它将根据模块的依赖关系进行静态分析,然后 ...

  4. 未能找到类型或命名空间名List

    解决方法添加引用using System.Collections.Generic;

  5. 一.JDK版本切换批处理脚本

    我们平时在window上做开发的时候,可能需要同时开发两个甚至多个项目,有时不同的项目对JDK的版本要求有区别,这时候我们可能会在一台电脑上安装多个版本的JDK,如下图所示:

  6. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误几种解决方案

    报错信息: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.study.ser ...

  7. jQuery通用的全局遍历方法$.each()用法实例

    1.jQuery通用的全局遍历方法$.each()用法 2. test.json文件代码: 3. html代码 4.jQuery代码 <script src="jquery-1.3.1 ...

  8. BZOJ5473: 仙人掌

    传送门 首先,所有连通块的个数的期望再减去每个点孤立的概率就是答案. 设 \(d_i\) 表示 \(i\) 的度数,那么每个点孤立的概率为 \(\frac{1}{2^{d_i}}\) 考虑计算所有连通 ...

  9. JS中的兼容问题总结

    今天总结总结在JS里面遇到的兼容性问题 1.获取滚动距离的兼容性问题: document.documentElement.scrollTop  ||  document.body.scrollTop ...

  10. springboot No Java compiler available for configuration options compilerClassName: [null] and compil

    今天使用eclipse创建springboot整合jsp出现一个问题,在idea中并没有遇到这个问题.最后发现是需要在eclipse中添加一个eclipse依赖,依赖如下: <dependenc ...