How can I open a file and add a line at the very beginning of that file, instead of appending my addition to the end of the file?
Take a look a Vincent's web site it describes how to do this.
http://www.hvt-automation.nl/yapf/faq.php?cmd=viewitem&itemid=15