Remove redundant file.close calls and variable assignment

Calling close() on files is redundant, files will automatically close when
going out of scope. Something like:

f = open(name,"r")
value = int(f.readline())
f.close()

is just a waste of resources, writing:

value = int(open(name,"r").readline())

is more efficient because it doesn't need to store and retrieve objects from
the namespace.

A file is an iterator, so instead of file.readlines() one can usually use the
file itself, instead of first reading it into a list. This also saves on
resources.