Blender as python module, 'Context' object has no attribute 'object'
Variables are not always available in the context, typically you can access them directly, in the case of the active object you can access it from 
scene.objects.active (most collections that have an active member work this way).