Here is the Python documentation of reading and writing files. That's probably the right place to start your investigation.