MiniBitePython - #2 Output result to .txt file with cmd | 使用cmd將結果輸出到.txt文件

疫情反覆,當大家安在家中,有沒有想學點什麼?
我在工作時有同事問起有關初學 Python 時的問題,希望可以有一些實用點的方式來學習,可惜網上缺少這種資訊。(說穿了是不太會使用Google)。所以我想創一個 Series,搞點簡單的 use case 來讓他學習。以下是系列記錄。

以下合適知曉如何使用Terminal的朋友。


Previously on miniBitePython,

前期提要,
MiniBitePython - #1 Create python .py script | 創建Python腳本

3. Output result to .txt file

  1. After we confirmed that our script calculates correctly. We want to output the result 4950 to a separate .txt since the python script will not store my result.

  2. Go to terminal and type in python sum_num.py > result.txt.
    This command will run the sum_num.py and then save the result (4950) to the result.txt. And if the .txt does not exist in the current directory, this command will help create one.

image.png

1.確認腳本正確計算後。 我們想要將結果4950輸出到獨立的“.txt中,因為python腳本不會存儲結果。

2.轉到終端並輸入python sum_num.py> result.txt
該命令將運行sum_num.py,然後將結果(4950)保存到result.txt。 如果當前目錄中不存在該命名的result.txt,則此命令將幫助創建一個。

Summary:

We learned to output a python script result in a .txt file with a terminal command.

摘要:
我們學會了使用終端命令將python腳本結果輸出到.txt文件中。



0
0
0.000
0 comments