sexta-feira, agosto 16, 2019

How to Run Your Python Scripts

How to Run Your Python Scripts One of the most important skills you need to build as a Python developer is to be able to run Python scripts and code. This is going to be the only way for you to know if your code works as you planned. It’s even the only way of knowing if your code works at all! This step-by-step tutorial will guide you through a series of ways to run Python scripts, depending on your environment, platform, needs, and skills as a programmer. You’ll have the opportunity to learn how to run Python scripts by using: The operating system command-line or terminal The Python interactive mode The IDE or text editor you like best The file manager of your system, by double-clicking on the icon of your script This way, you’ll get the knowledge and skills you’ll need to make your development cycle more productive and flexible. What’s the Python Interpreter? Python is an excellent programming language that allows you to be productive in a wide variety of fields. Python is also a piece of software called an interpreter. The interpreter is the program you’ll need to run Python code and scripts. Technically, the interpreter is a layer of software that works between your program and your computer hardware to get your code running. Depending on the Python implementation you use, the interpreter can be: A program written in C, like CPython, which is the core implementation of the language A program written in Java, like Jython A program written in Python itself, like PyPy A program implemented in .NET, like IronPython Whatever form the interpreter takes, the code you write will always be run by this program. Therefore, the first condition to be able to run Python scripts is to have the interpreter correctly installed on your system. The interpreter is able to run Python code in two different ways: As a script or module As a piece of code typed into an interactive session How to Run Python Code Interactively A widely used way to run Python code is through an interactive session. To start a Python interactive session, just open a command-line or terminal and then type in python, or python3 depending on your Python installation, and then hit Enter. Source: https://realpython.com/run-python-scripts/