Quick Tip: How to Print a File Path of a Module

Python provides a really easy and simple way of retrieving file paths of an imported module. This can be really helpful if you’re trying to find a file path quickly and you’re working on a project that has multiple subdirectories, or if you’re using scripts or programs that are primarily accessed through the command line. If […]

Read More

Understanding Python’s Numeric Types

Numeric data types in Python are used to store numeric values. Python has four defined numeric types: plain integers, long integers, floating values, and complex numbers. The int type (plain integers) represents whole numbers that can be either positive or negative. The long type (long integers) are integers of infinite size. They’re written as whole […]

Read More

How to Use the Enumerate() Function

In Python, the enumerate() function is used to iterate through a list while keeping track of the list items’ indices. To see it in action, first you’ll need to put together a list: pets = (‘Dogs’, ‘Cats’, ‘Turtles’, ‘Rabbits’) Then you’ll need this line of code: for i, pet in enumerate(pets): print i, pet Your output should […]

Read More

The Basics: When to Use the del Statement

Using the del statement is relatively straightforward: it’s used to delete something. Often it’s used to remove an item from a list by referring to the item’s index rather than its value. For example, if you have the following list: list = [4, 8, 2, 3, 9, 7] And you want to remove the number […]

Read More

Migrate SQLAlchemy Databases with Alembic

Alembic Alembic is a lightweight database migration tool for SQLAlchemy. It is created by the author of SQLAlchemy and it has become the de-facto standard tool to perform migrations on SQLAlchemy backed databases. Database Migration in SQLAlchemy A database migration usually changes the schema of a database, such as adding a column or a constraint, […]

Read More

SQLAlchemy Expression Language, More Advanced Usage

Overview In the previous article SQLAlchemy Expression Language, Advanced Usage, we learned the power of SQLAlchemy’s expression language through a three table database including User, ShoppingCart, and Product. In this article, we are going to review the concept of materialised path in SQLAlchemy and use it to implement product containing relationships, where certain products may […]

Read More

SQLAlchemy Expression Language, Advanced Usage

Expression Language One of the core components of SQLAlchemy is the Expression Language. It is allows the programmer to specify SQL statements in Python constructs and use the constructs directly in more complex queries. Since the expression language is backend-neutral and comprehensively covers every aspect of raw SQL, it is closer to raw SQL than […]

Read More

Understanding Python SQLAlchemy’s Session

What are SQLAlchemy Sessions? What does the Session do? One of the core concepts in SQLAlchemy is the Session. A Session establishes and maintains all conversations between your program and the databases. It represents an intermediary zone for all the Python model objects you have loaded in it. It is one of the entry points […]

Read More

SQLAlchemy Association Tables

Association Tables In our previous articles, we used an association table to model many-to-many relationships between tables, such as the relationship between Department and Employee. In this article, we are going to dive deeper into the association table concept and see how we can use it to further solve more complicated problems. DepartmentEmployeeLink and Extra […]

Read More

SQLAlchemy ORM Examples

ORM Recap In one of the previous articles, we briefly went through an example database with two tables department and employee where one department can have multiple employees and one employee can belong to arbitrary number of departments. We used several code snippets to demonstrate the power of SQLAlchemy’s expression language and show how to […]

Read More