Tgbranch

You can use the "with open" style here, just like you did for the file reading, and avoid having to close the file later.