The difference between os.path.exists (path) and os.path.lexists (path)

Source: Internet
Author: User
Use the Os.path.exists () method to directly determine whether a file exists.
The code is as follows:
>>> Import OS
>>> os.path.exists (R ' C:\1.TXT ')
False


Os.path.exists (PATH)
Return True If path refers to an existing path. Returns False for broken symbolic links. On some platforms, this function could return False if permission is not granted to execute Os.stat () on the requested file, Even if the path physically exists.

Os.path.lexists (PATH)
Return True If path refers to an existing path. Returns True for broken symbolic links. Equivalent to exists () on platforms Lackingos.lstat ().
The main difference is that exists () automatically determines the invalid file link. If the checked file is a soft link, but the file that the soft connection points to is deleted, it returns false. and lexists () does not do this check, as long as the soft connection exists, even if the file it points to does not exist, it also returns true.


The difference between os.path.exists (path) and os.path.lexists (path)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.