os.access('sample.txt', os.W_OK) #Output False f = open("sample.txt", "x") # create the file #check again os.access('sample.txt', os.W_OK) #Output True