The BGE API does not provide the relationship from a game object to the scene it lives in. At present the only way to get this is to search through all scenes to find the reference of the game object, which is inefficient.
This patch extends the KX_GameObject python api with the function .getScene() which returns the KX_Scene object the calling game object resides in. This feature was requested on the BA forums (http://blenderartists.org/forum/showthread.php?258354-BGE-proposal-Scene-access-from-game-object), so I thought I'd have a go at implementing it.
Description
Event Timeline
This patch does not return the scene the object belongs to, but the currently active scene, which won't work if you're looking at objects in another scene. In other words, any object accessed at the same time will have the same active scene (the scene from which the Python controller was activated). Also, this really should be a property instead of a function. You'll need to add a KX_PYATTRIBUTE_RO_FUNCTION to KX_GameObject::Attributes[], and you'll need to create a function similar to KX_GameObject::pyattr_get_parent().
Thanks for the feedback! I understand where I was going wrong now, and it's helped me figure out another bug I was looking at too. I've uploaded my second attempt, I'd be grateful if you could take a look. Cheers!
The second patch looks fine to me. However, it would probably be good to have Campbell double check this.