Uncategorized
Python Code Snippets: Solving the Quadratic Equation
Here’s a fun way to use Python: input any three numbers into a function and you can solve the quadratic equation in milliseconds. Bet you wish you knew about this one back when you were in Algebra I class. The function, written by the people over at Programiz, solves the quadratic equation using basic multiplication […]
Read MoreImage Processing with Pillow for Python
If you’ve ever tried to process images on Python and found it to be a total pain, Pillow is here for you. You might know that PIL (Python Imaging Library) has a lot of problems and limitations, and it doesn’t really seem to be in development (it’s hardly ever updated or changed). Here’s where Pillow […]
Read MoreBeautiful Soup: A Web Scraper for Python
If you ever need to extract data from a Python site or file quickly and easily, Beautiful Soup, a library designed to help with things like web scraping, is here for you. Beautiful Soup is built on top of popular Python parsers lxml and html5lib, and it’s great for web scraping because it automatically converts […]
Read MorePython Snippets: How to Generate Random String
Python can be a really useful tool to do things like creating random strings. There could be dozens of different reasons why you might want to create a random string of characters and numbers, but one of the more common ones is to use this string as a password. Python Code Snippets offers this really […]
Read MoreQuick 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 MoreUnderstanding 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 MoreHow to Use the Enumerate() Function
Iterables are undoubtedly some of the most valuable objects in Python. They’re incredibly versatile, helping solve a large assortment of problems. Looping through iterables is an extremely common task, but keeping track of the current element’s index typically demands writing more code. This is why the enumerate() function was built into Python all the way […]
Read MoreThe 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 MoreMigrate 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 MoreSQLAlchemy 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