Posted By

GabrielTheodoulos on 07/20/16


Tagged

file io os


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

BigD3m0n
svendb7


Search to see if a File Exists


 / Published in: Python
 

URL: https://www.youtube.com/watch?v=wgHeTJtth0w

The os module is to help you deal with any operation dealing with the directory.

  1. import os
  2.  
  3. # todo check for existing file.
  4. if os.path.isfile('./gradebook.dat'): # check to see if file exists
  5. data = open('./gradebook.dat', 'rb') # if file exists open, read all data.
  6. data.close()
  7. else:
  8. print("The file gradebook.dat was not found.\n")
  9. print("We will create one....\n")

Report this snippet  

You need to login to post a comment.