How can i write a simple keylogger with Python and how to append it to another file and send it?

How did i mail the logged keys to myself?

Thank you