How to run python code from Windows console

I am quite new to python programming but happy to use it for quick test cases like API calls or file operations. To run these scenarios I run them in different ways:

From file

One of the easiest way to call your script is to store them in a file and make python run them:

print('I am run from a file!')

content of run-me.py

Run it from command line:

python run-me.py

From inline command line

If you don’t want to save your code to a file, you can run it from inline:

python -c "print('I am from inline command line')"

From inline command line, multi line

Normally python code is segmented by new lines and indentation, but inline we can separate commands by semicolons:

One thought on “How to run python code from Windows console

  1. Python Training in Chennai

    Greetings of the day Dávid’s Dev, In this small article you had explained about “How to run python code from Windows console”. It was short and descriptive. Also you had added more details on From file, and From inline command line. Thanks for your Info!!!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.