Blotting in C++, i had forgotten how easy python is.
I am guessing you are using windows cos you didn't put a shibang at the start of the code. It is wiser to do it for code portability since it save *nix alot of complaints and tells it where to find the python binary.
Your variables could use a little self explaining as in verbosity than 'a', 'f' tho am okay with the requests 'r' variable but i tend to use 'res'.
I am not sure which mode you opened 'f' in, read, write or both? Careful.
Do you realise you never closed any of both the files you open? That is bad news.
It is good practice to print you exceptions so as to provide for better debugging.
Also assuming this is python 3, write more code and read more.