sethserver / python

Python

Why is Python So Popular Despite Being Slow?

Python

Let me reframe this question using different technology. Why are Toyota Corollas so popular despite being so slow? They're obviously much slower than rocket powered aircraft! Things just got crazy, right? Let's do some math to prove our point about how slow Toyota Corollas really are when compared to rockets. read on »

How to Avoid KeyError

Python

When working with Python dictionaries you'll find yourself needing to access a key that may or may not exist. The easiest way to do this is with the get() method. read on »

Seth's Guide to Setting up Your Python Environment

Python

Python is an amazing language and it's easy to get started. However, there are a few things you should do to ensure your environment is setup properly. read on »

How For Loops Work in Python

Python

Python has some pretty amazing features, and one of its most powerful and versatile is the for loop. As you can see by the examples below the for loop in Python is quite powerful when used in conjunction with... read on »

Generate a Secure Random Password

Python

The conciseness of the Python language paird with its easy-to-use REPL make it ideal to hack out quick and easy scripts. One thing you can do is quickly and securely generate a random password with practically one line of code. read on »

How to Fix a B0rked Python Environment

Python

If you've spent any time working with Python environments you're bound to have run into errors such as pip: command not found, No module named pip, ModuleNotFoundError: No module named 'distutils.util', or other Python 2.x vs Python 3.x issues. read on »

How to Tell if a File Exists in Python

Python

Python helps make a lot of things really easy. The conciseness of the language make it awesome to accomplish simple tasks in as few lines as possible. One of these simple tasks is checking to see if a file exists. read on »

Logger Defaults to WARN

Python

When debugging and profiling Python software you'll find yourself relying on Python's built-in logging module. Something that is very simple to overlook is the fact that the root logger defaults to WARN and not DEBUG. read on »

How to Read a File Line by Line

Python

When using Python for Data Science or general Programming you'll find yourself needing to read and parse very very very large files. The easiest way to accomplish this is by iterating over the actual file object. read on »

Recursively List Files

Python

When using Python for Data Science or general Systems Administration you'll find yourself needing to recursively read a directory tree, remember all (or some) of the files in the directories and then do something fun with those files. read on »

Secret Santa Gift Exchange

Python

My wife is in charge of our families' annual Secret Santa Gift Exchange. Because she, unfortunately, knows about my background in math and computer science her requirements have become more extreme. read on »

TypeError: Object is not JSON serializable

Python

When working with Python dictionaries you'll find yourself needing to access a key that may or may not exist. The easiest way to do this is with the get() method. read on »

Understanding Slice Notation

Python

In my mind the easiest way to understand Python's slice notation is to visualize it with real examples. Once you get it under your fingers you'll find list slicing is an invaluable tool to have in your Python toolkit. read on »