run python code example

Example 1: run python file using python code

exec(open('file.py').read())

Example 2: python run command

import os
os.system('cmd /k "Your Command Prompt Command"')

Example 3: how to run a python script

# Save the script in a file with .py extension
# run the script using the below command
python fileName.py

Example 4: python how to run terminal command

#By Uku Loskit

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

Example 5: 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 6: how to run a python package from command line

python -m my_course.filter

Tags:

Html Example