Rgr. I knew there was something better. Borrowed from Python here.