Quick Tip: Using Sets in Python

In Python, sets are lists that don’t contain any duplicate entries. Using the set type is a quick and easy way to make sure that a list doesn’t contain any duplicates. Here’s an example of how you would use it to check a list for duplicates: a = set([“Pizza”, “Ice Cream”, “Donuts”, “Pizza”]) print a […]

Read More

Python’s SQLAlchemy vs Other ORMs

Overview of Python ORMs As a wonderful language, Python has lots of ORM libraries besides SQLAlchemy. In this article, we are going to take a look at several popular alternative ORM libraries to better understand the big picture of the Python ORM landscape. By writing a script that reads and writes to a simple database […]

Read More

Python’s Django vs Ruby on Rails

Python vs Ruby Ruby is a dynamic, reflective, object-oriented general-purpose programming language which was designed and developed in the mid-1990s. Compared to Python, which treats code readability above everything else, the philosophy behind Ruby is that programmers should have the flexibility, freedom and power to write concise and compact code. The most important difference between […]

Read More

How to Install Django on Windows, Mac and Linux

In this article, we are going to learn how to install Django on Windows, Mac and Linux. Since Mac and Linux are both derived from the Unix platform, the instructions about installing Django on Mac and Linux are almost identical to each other and we will present them in the same section. Windows, however, is […]

Read More

How to Install SQLAlchemy

In the previous article of the series Introductory Tutorial to Python’s SQLAlchemy, we learned how to write database code using SQLAlchemy’s declaratives. In this article, we are going to learn how to install SQLAlchemy on Linux, Mac OS X and Windows. Installing SQLAlchemy on Windows Before installing SQLAlchemy on Windows, you need to install Python […]

Read More

Time a Python Function

In one of the previous articles (Measure Time in Python – time.time() vs time.clock()), we learned how to use the module timeit to benchmark a program. Since the program we timed in that article includes only raw statements instead of functions, we’re going to explore how to actually time a function in Python. Time a […]

Read More

Hashing Files with Python

Remember that a hash is a function that takes a variable length sequence of bytes and converts it to a fixed length sequence. Calculating a hash for a file is always useful when you need to check if two files are identical, or to make sure that the contents of a file were not changed, […]

Read More

Hashing Strings with Python

A hash function is a function that takes input of a variable length sequence of bytes and converts it to a fixed length sequence. It is a one way function. This means if f is the hashing function, calculating f(x) is pretty fast and simple, but trying to obtain x again will take years. The value returned […]

Read More

How to Recursively Copy a Folder (Directory) in Python

Ever tried to copy a directory/folder in Python? Ever failed? No matter. Try again! If you haven’t already read it, look at the article How to Copy a File in Python with shutil for an explanation of how to copy files with shutil. Recursively Copying a Directory/Folder of Files in Python In the article that […]

Read More

How to Rename (Move) a File in Python

Renaming (in Python it’s known as moving) a file in Python is really simple, and can be done in very few lines thanks to a handy module called shutil. shutil has a function called move that does precisely what the function name implies. It moves files or directories from one location to another. Here’s a […]

Read More