As a friendly heads up, you should avoid using the global statement and avoid opening files without using with.