os.path.exists()是从哪里找?

假设要搜索一个文件,那么是从哪些路径里找,sys.path里吗,还是...

这取决于你传给exists的参数:如果参数是绝对路径(文件或文件夹),自然是搜索这个绝对路径;如果参数是相对路径,则是从当前路径下搜索。执行os.getcwd()可以返回当前路径。

>>> import os
>>> os.path.exists(r'D:\XufiveGithub\wxgl') # 使用绝对路径
True
>>> os.getcwd() # 返回当前路径
'C:\\Users\\xufive\\AppData\\Local\\Programs\\Python\\Python37'
>>> os.path.exists(r'python.exe') # 在当前路径下搜索python.exe
True

看你是搜索什么文件了,os.path是python的搜索模块的路径集,是一个list,要找在其他目录自定义的文件,就参考:https://www.cnblogs.com/Lclkris/p/8724711.html