print(os.access('sample.txt', os.R_OK)) # Output False f = open("sample.txt", "x") #create the file #check again print(os.access('sample.txt', os.R_OK)) # Output True
Here is what the above code is Doing:
1. We are checking if the file sample.txt is readable or not.
2. Since the file doesn’t exist, it returns False.
3. We create the file using the open() function.
4. We check again if the file is readable or not.
5. Since the file exists, it returns True.