What is the python equivalent of below perl code? : I am trying to capture the result of a command in python.

    use Capture::Tiny ':all';
    my ($stdout, $stderr, $exit_code) = capture {
        system( "$cmd");
    };
