Real Python: Python Scope & the LEGB Rule: Resolving Names in Your Code

The concept of scope rules how variables and names are looked up in your code. It determines the visibility of a variable within the code. The scope of a name or variable depends on the place in your code where you create that variable. The Python scope concept is generally presented using a rule known as the LEGB rule. The letters in the acronym LEGB stand for Local, Enclosing, Global, and Built-in scopes. This summarizes not only the Python scope levels but also the sequence of steps that Python follows…

Read More

Real Python: Using the Python defaultdict Type for Handling Missing Keys

A common problem that you can face when working with Python dictionaries is to try to access or modify keys that don’t exist in the dictionary. This will raise a KeyError and break up your code execution. To handle these kinds of situations, the standard library provides the Python defaultdict type, a dictionary-like class that’s available for you in collections. The Python defaultdict type behaves almost exactly like a regular Python dictionary, but if you try to access or modify a missing key, then defaultdict will automatically create the key…

Read More

Real Python: Defining Main Functions in Python

Many programming languages have a special function that is automatically executed when an operating system starts to run a program. This function is usually called main() and must have a specific return type and arguments according to the language standard. On the other hand, the Python interpreter executes scripts starting at the top of the file, and there is no specific function that Python automatically executes. Nevertheless, having a defined starting point for the execution of a program is useful for understanding how a program works. Python programmers have come…

Read More
Programming 

Real Python: Defining Your Own Python Function

Throughout the previous tutorials in this series, you’ve seen many examples demonstrating the use of built-in Python functions. In this tutorial, you’ll learn how to define your own Python function. You’ll learn when to divide your program into separate user-defined functions and what tools you’ll need to do this. Here’s what you’ll learn in this tutorial: How functions work in Python and why they’re beneficial How to define and call your own Python function Mechanisms for passing arguments to your function How to return data from your function back to…

Read More

Real Python: Null in Python: Understanding Python's NoneType Object

If you have experience with other programming languages, like C or Java, then you’ve probably heard of the concept of null. Many languages use this to represent a pointer that doesn’t point to anything, to denote when a variable is empty, or to mark default parameters that you haven’t yet supplied. null is often defined to be 0 in those languages, but null in Python is different. Python uses the keyword None to define null objects and variables. While None does serve some of the same purposes as null in…

Read More

Real Python: Use a Flask Blueprint to Architect Your Applications

Flask is a very popular web application framework that leaves almost all design and architecture decisions up to the developer. In this tutorial, you’ll learn how a Flask Blueprint, or Blueprint for short, can help you structure your Flask application by grouping its functionality into reusable components. In this tutorial, you’ll learn: What Flask Blueprints are and how they work How to create and use a Flask Blueprint to organize your code How to improve code reusability using your own or a third-party Flask Blueprint This tutorial assumes that you…

Read More

Andre Roberge: Friendly-traceback, Real Python, Pycon, and more

After an interruption that lasted a few months, I’ve finally been able to return to programming, more specifically working mostly on Friendly-traceback. For those that do not know Friendly-traceback: it aims to replace the sometimes obscure traceback generated by Python with something easier to understand. Furthermore, Friendly-traceback is designed with support for languages other than English so that, in theory, beginners (who are the main target audience for Friendly-traceback) could benefit no matter what their native language is … provided someone would have done the translation into that language, of…

Read More
css 

Real Python: Python REST APIs With Flask, Connexion, and SQLAlchemy – Part 4

In Part 3 of this series, you added relationships to the REST API and to the database that supports it. This gave you a powerful tool you can use to build interesting programs that send persistent data, as well as the relationships between that data, to a database system. Having a REST API gives you the ability to create a Single-Page Application (SPA) with HTML, CSS, and JavaScript. This is a good starting point before you make the jump to more powerful front-end frameworks, like Angular or React. In this…

Read More
Programming 

Internet Festival 2019 – Zerynth demonstrates real Industry 4.0 opportunities for companies and professionals

Last week we were lucky to hold two events at the annual Pisa Internet Festival. The morning event covered the topic of Industry 4.0 and the 4ZeroPlatform, while the evening event covered the implementation of Industry 4.0 strategies and technologies with the Zerynth tools. As you can see, we handled some pretty popular topics and questions. But since we’re experts in the field of IoT and Industry 4.0, we thought it would be useful for developers and professionals to hear what we have learned so far, and what they can…

Read More