Instead of this:
FILE = open(f) do_something(FILE) FILE.close()
it\'s better to use this:
with open(f) as FILE: do_some
This seems to solve all of your concerns.
if file_name is not None: with open(file_name) as fh: do_something(fh) else: do_something(None)