def get_rational_coeffs(expr):
    num, denom = expr.as_numer_denom()
return [sp.Poly(num, x).all_coeffs(), sp.Poly(denom, x).all_coeffs()]
a, b, c, d, x, s = sp.symbols('a b c d x s')
expr = (a + b * x) / (c + d * x)
(n1, n0), (d1, d0) = get_rational_coeffs(s * expr)
print(((n0, n1), (d0, d1)))
In sympy, how do I get the coefficients of a rational expression?