zoukankan      html  css  js  c++  java
  • 【Python】os.path.isfile()的使用方法汇总

    方法一:

     1 # -*- coding:utf-8 -*-
     2 import os
     3 import sys
     4 from uiautomator import device as d
     5 
     6 filepath = r'E:ProjectA3A_8_4Gexerciseapp_listhello.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()中传入绝对路径,但需要注意的是需要将号进行转义,不然也会报错了

  • 相关阅读:
    Eclipse中properties文件中文显示编码、乱码问题
    Eclipse中安装yml插件( YEdit )
    Java中如何返回Json数组
    ASIFormDataRequest 登录
    Safari里使用JsonView
    beginUpdates和endUpdates
    svn log 不显示日志的问题
    svn代码回滚命令
    Tomcat: localhost:8080 提示404
    android定时三种方式
  • 原文地址:https://www.cnblogs.com/aziji/p/9335779.html
Copyright © 2011-2022 走看看