How to run a Python file at a Windows 10 command prompt

Introduction

If you haven't installed Python yet, I recommend this article because it is easy to understand and short. By the way, the version of my Python is 3.8.0, but there is no problem if it is a Python3 system.

Creating a python file

First, copy and paste the following script into a text editor, etc., and save it with the extension .py. Here, the file name is sample.py and the save destination is in the Desktop folder.

sample.py


print("Hello World!!")

In Python3 series, if you write print (), the one in parentheses will be output. If you want to output a character string, enclose it in double quotation marks "".

Start command prompt

In Windows 10, you can easily find the command prompt by pressing this magnifying glass at the bottom left of the screen and searching for cm. cm is an acronym for command. image.png If the magnifying glass is not at the bottom left of the screen, right-click on the taskbar to display the search icon.

Executing a Python file

Did you start the command prompt? When you start it, you should see the following screen. Hidden in blue is my name. image.png If you can start it, type the command cd desktop here to move to the folder containing the Python files. If you can move to the folder where the Python files are, type the command python sample.py. image.png If Hello World !! is displayed like this, you are successful!

At the end

In fact, Python files can also be run by double-clicking them directly.

However, this method closes the window after the program has been processed to the last line. To see the output, you need to write ʻinput ()` on the last line of your program.

Also, even if you write ʻinput ()`, if there is an error in the program, the window will be forcibly closed at that point, so you will not know the error content (at the command prompt, tell me the error content and location. Will do it).

Therefore, for ease of debugging, run Python files at the command prompt.

Recommended Posts

How to run a Python file at a Windows 10 command prompt
How to run a Maya Python script
How to read a CSV file with Python 2/3
How to create a JSON file in Python
How to install Python [Windows]
How to run Notepad ++ Python
A memorandum to run a python script in a bat file
How to execute a command using subprocess in Python
How to run Django on IIS on a Windows server
It's easier to iterate over a python file from a command prompt (cmd) .bat
How to write a Python class
Hit a command in Python (Windows)
How to run a Python program from within a shell script
How to shuffle a part of a Python list (at random.shuffle)
How to import a file anywhere you like in Python
[Python] How to output a pandas table to an excel file
How to create a config file
Create a shell script to run the python file multiple times
How to make a command to read the configuration file with pyramid
How to get a string from a command line argument in python
How to specify a .py file to load at startup in IPython 0.13
How to output the output result of the Linux man command to a file
[Python] How to store a csv file as one-dimensional array data
[ROS2] How to play a bag file with python format launch
[Python] How to convert db file to csv
[Python] How to make a class iterable
[Kivy] How to install Kivy on Windows [Python]
[Python] How to convert a 2D list to a 1D list
How to convert Python to an exe file
[python] How to use __command__, function explanation
[Python] How to invert a character string
How to get a stacktrace in python
[Python / Tkinter] How to pass arguments to command
Call a command from Python (Windows version)
Create a shortcut to run a Python file in VScode on your terminal
How to hide the command prompt when running python in visual studio 2015
How to put a line number at the beginning of a CSV file
[Python] How to read a csv file (read_csv method of pandas module)
[Python] How to test command line parser click
How to disguise a ZIP file as a PNG file
How to receive command line arguments in Python
Put MicroPython on Windows to run ESP32 on Python
How to create a Python virtual environment (venv)
How to open a web browser from python
How to clear tuples in a list (Python)
How to hold a competition at Coda Lab
How to embed a variable in a python string
How to implement Discord Slash Command in Python
[Python] How to read excel file with pandas
How to run MeCab on Ubuntu 18.04 LTS Python
How to generate a Python object from JSON
How to add a Python module search path
How to notify a Discord channel in Python
How to create a shortcut command for LINUX
How to add Anaconda Powershell Prompt to Windows Terminal?
Export Python3 version OpenCV KeyPoint to a file
How to live a decent life on 2017 Windows
How to run Leap Motion in non-Apple Python
Run a Python file from html using Django
[Python] How to draw a histogram in Matplotlib
[Python] How to install OpenCV on Anaconda [Windows]