码迷,mamicode.com
首页 > 编程语言 > 详细

【Python】os.path.isfile()的使用方法汇总

时间:2018-07-19 16:06:41      阅读:2486      评论:0      收藏:0      [点我收藏+]

标签:import   使用方法   filename   直接   path   project   tor   pre   tomato   

方法一:

 1 # -*- coding:utf-8 -*-
 2 import os
 3 import sys
 4 from uiautomator import device as d
 5 
 6 filepath = rE:\Project\A3A_8_4G\exercise\app_list\hello.apk
 7 
 8 if os.path.isfile(filepath):
 9     print "true"
10 else:
11     print "false"

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

方法二:

 1 # -*- coding:utf-8 -*-
 2 import os
 3 import sys
 4 from uiautomator import device as d
 5 
 6 filepath = sys.path[0] + "\\app_list\\"
 7 filename = "hello.apk"
 8 
 9 if os.path.isfile(os.path.join(filepath,filename)):
10     print "true"
11 else:
12     print "false"

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

方法三:

1 # -*- coding:utf-8 -*-
2 import os
3 import sys
4 from uiautomator import device as d
5 
6 if os.path.isfile(E:\\Project\\A3A_8_4G\\exercise\\app_list\\hello.apk):
7     print "true"
8 else:
9     print "false"

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

【Python】os.path.isfile()的使用方法汇总

标签:import   使用方法   filename   直接   path   project   tor   pre   tomato   

原文地址:https://www.cnblogs.com/51study/p/9335779.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!