First make sure that Python is able to read the path to your file.
from os import path
if path.exists('ranks.dat'):
# do the file processing
else:
print('Filepath does not exist.')
In addition, you can also use a `context manager` to open and close the file for you when you are done
with open('ranks.dat', 'r') as f:
for line in f.readlines():
print(line)