-
Software Development Terms and Acronyms
Learn some common acronyms and terms used in software development.
-
How to Specify Default List Value with Types in Python
Imagine you have a Python function that takes a list as a parameter. And you would like to use mypy to indicate that a_list is indeed of type List, then you would have: This is pretty straightforward, but if you want to give a_list a default value, things get a little tricky. You probably already…
-
Don’t Use Mutable Default Values in Python Functions
Perhaps you have heard the advice that you shouldn’t use mutable default values in Python functions, here is why. Here is a simple function (about as simple as you can get) that takes one parameter my_list with a default value of [1, 2, 3] and returns that same list. Now, let’s call the function and…
-
What is if __name__ == ‘__main__’ and why would I use it in Python?
You may have seen the line (usually at the end of a Python script): And wondered what it does, and why it is there. After reading this you will never wonder why again! What does it do? In short, if __name__ == ‘__main__’: only runs the body of the if block if it the file…
-
What exactly is a Python package?
In Python, the term package has a very specific meaning that may be different than what you initially expect. Furthermore, a deep understanding of what exactly a package is doesn’t only allow you to correct your friends at parties (because you talk about Python at parties… right?), but is integral to being able to separate…
-
Properly Calculate Memory Size of Python Object
You are a conscientious developer and want to ensure that your Python program isn’t using too much memory, because ya know, it is the right thing to do. Or perhaps you are analyzing a large dataset and have already run out of RAM on your laptop… so you need to optimize your objects to see…
-
How to debug an AttributeError in Python
Whether you have written 10 lines of Python or 10,000 lines it is always surprising when you get an AttributeError exception in your code. By the end of this post you will be well on your way to learning why this happens and how can you fix it.