This approach uses:
- almost no internal punctuation by using a triple quoted string
- strips away local indentation using the
inspectmodule - uses Python 3.6 formatted string interpolation ('f') for the
account_idanddef_idvariables.
This way looks the most Pythonic to me.
import inspect query = inspect.cleandoc(f''' SELECT action.descr as "action", role.id as role_id, role.descr as role FROM public.role_action_def, public.role, public.record_def, public.action WHERE role.id = role_action_def.role_id AND record_def.id = role_action_def.def_id AND action.id = role_action_def.action_id AND role_action_def.account_id = {account_id} AND record_def.account_id={account_id} AND def_id={def_id}''' )