Fix rmagic for Python 3