Check whether a path is valid in Python

前端 未结 2 1009
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-15 11:52

Is there any easy way to check whether a path is valid? The file doesn\'t have to exist now, I\'m wondering if it could exist.

my current version is this:



        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 12:17

    You can also try the below:

    import os  
    if not os.path.exists(file_path):
        print "Path of the file is Invalid"
    

提交回复
热议问题