Why not use string formatting? `format(ob_id, 'x')` or `{0:x}.format(ob_id)` would avoid the need to strip both the leading `0x` and the possible trailing `L`.