Let's learn how to run Python scripts from CMD if you are using machines with Windows.
On Windows 10, click in lower left corner where we have search box. Type "cmd"
there and press Enter. This is what will pop-up (in my case):
Microsoft Windows [Version 10.0.18363.959]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\user>
This is default directory for user. To clear screen type "cls"
and press Enter.
After that, let's move to place where I have Python installed, using "cd"
command. I have Python in "Python38-64" directory inside "root" of my hard drive:
C:\Users\user>cd C:\Python38-64
C:\Python38-64>
Now, what is in that directory ? We will use "dir"
command to list content:
C:\Python38-64>dir
Volume in drive C is New Volume
Directory of C:\Python38-64
07/30/2020 11:50 AM <DIR> .
07/30/2020 11:50 AM <DIR> ..
07/30/2020 11:50 AM <DIR> ARCHIVE
06/22/2020 04:59 PM <DIR> DLLs
05/30/2020 04:27 PM <DIR> Doc
06/22/2020 06:04 PM <DIR> include
05/30/2020 04:27 PM <DIR> Lib
05/30/2020 04:27 PM <DIR> libs
05/13/2020 10:43 PM 31,453 LICENSE.txt
07/30/2020 12:00 AM 34 playground.py
05/13/2020 10:42 PM 100,424 python.exe
05/13/2020 10:42 PM 58,952 python3.dll
05/13/2020 10:42 PM 4,208,200 python38.dll
07/27/2020 02:10 PM <DIR> Scripts
05/30/2020 04:28 PM <DIR> tcl
05/30/2020 04:27 PM <DIR> Tools
05/13/2020 10:43 PM 100,880 vcruntime140.dll
05/13/2020 10:43 PM 44,320 vcruntime140_1.dll
7 File(s) 4,544,263 bytes
11 Dir(s) 74,980,769,792 bytes free
C:\Python38-64>
That is our listing. Important thing here is python.exe file, and also we see our custom playground.py file. Ok, now we can run our custom python script, with python playground.py
C:\Python38-64>python playground.py
0
1
2
3
4
C:\Python38-64>
After script is executed, you are again in cmd, which means we can continue to run other python scripts (if we have it), or we can just type classical MS-DOS command.
You don't need to use CMD if you don't like typing, working in IDLE is perfectly fine. But knowing how to navigate through system using cmd on Windows, or Terminal on Linux/BSD system is important for programmers.
Ok, in next tutorial we will talk about syntax and indentation in Python.
No comments:
Post a Comment