1. 程式人生 > 其它 >python 輸出結果到txt_輸出python的help結果到檔案中

python 輸出結果到txt_輸出python的help結果到檔案中

技術標籤:python 輸出結果到txt

#1.命令列方式:
  python -c "import sys; help(sys.exit)" > help.txt

#2.函式程式碼的方式輸出
def help_output(help_element):
    filename = 'help.txt'

    stdout = sys.stdout
    out_file = open(filename, 'w+')
    sys.stdout = out_file

    help(help_element)
    out_file.flush()

    out_file.close()
    sys.stdout = stdout