[enh] Added output function that returns a file object