664 python code gen

Fix for python code generator. Now produces code for logged in users which is actually correct.