Other answers did not work for me on Windows within an interactive python session. I cannot do it from a command line as I need help on a COM object. I used the output argument mentioned by Clifford
def help_to_file(func, out_file="function_help.txt"):
try:
with open(out_file, "w") as f:
h2f = pydoc.Helper(output=f)
h2f(func)
print(f"Help for '{func}' written to '{out_file}'")
except Exception as e:
print(f"Error writing help: {e}")
Then to use it:
help_to_file(str, "_str.txt")