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()中传入绝对路径,但需要注意的是需要将号进行转义,不然也会报错了

  • 相关阅读:
    对象比较
    ObservableCollection<T> 的同类 ListCollectionView
    数据模板--DataTemplate
    ListBox的虚拟可视化技术
    WPF 动画 和 色彩 的随笔
    Binding.RelativeSource 属性
    javascript基础DOM操作
    js dom 操作技巧
    js 内置对象和方法 示例
    javascript 编程技巧
  • 原文地址:https://www.cnblogs.com/aziji/p/9335779.html
Copyright © 2011-2022 走看看