Rewrite xdsc in Python