It's better to use "with open(infile, "r") as fd" approach everythere you have to deal with files.