execute python script windows code example

Example 1: run python.py file

# save a file in text editor with .py
# open terminal, and change directories
# run the following command:
python3 file.py

Example 2: python how to run terminal command

#By Uku Loskit

import os
os.system("ls -l")

Example 3: how to run python file from cmd

// To run pytho script from CMD
// type python and the name of the file. Assuming hello.py

python hello.py

Example 4: Windows 10 running python scripts from cmd

# move to the directory where the script is located and run it like so
cd (path to directory)
python name.py

Example 5: python fuction execute a script site:realpython.com

>>> exec(open('hello.py').read())
'Hello World!'

Example 6: how to execute a python script

C:\Python27\python.exe C:\Users\Username\Desktop\my_python_script.py