When I execute the following line in my script:
if os.path.exists('/home/jsc0606/Desktop/project/myfile.py')
I get False
. However, when I execute the same line in the terminal in the same directory, I get True
. Does anyone know why Python can't find the file when executing that line in the script?
As stated in the docs about os.path.exists
:
On some platforms, this function may return
False
if permission is not granted to executeos.stat()
on the requested file, even if the path physically exists.
I think this may be the case: you're probably running the script with different privileges.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.