There are a few different approaches for writing tests for date and/or time-sensitive functionality. One could choose to add a sleep() in the test, which would guarantee that the time passed, but that also has the downside of increasing the run time of the test. Another option is to reach out to external libraries or … Continue reading TIL: time travel with Python’s standard library
Tag: python
Django Rest Framework: adding DateTimeField format serializer validation
Adding date and time format validation to a DRF serializer
TIL: installed packages in Python – list, and show
If your Python project has a very short list of required packages (in requirements, pipfile, etc), it's easy to see all packages you have. But on large projects, the dependencies can run pretty long, not to mention the dependencies for the required packages. And what about learning more about those dependencies? pip list Will list … Continue reading TIL: installed packages in Python – list, and show
A caller id for your python function
Most of you might be too young to know this but there was time that the phone in your house - not in your pocket! - would ring and gasp! you had no idea who was calling! You had to ANSWER the phone to find out. 🤦♀️ Now we have caller ID and know exactly … Continue reading A caller id for your python function
Getting started with gRPC – part II: the code
In a previous post I wrote a summary of the things I learned about gRPC. Here I will talk about the prototype app I wrote to test gRPC and gRPC-Web. About my prototype As I mentioned before, I wrote a prototype app that tests if the string that the user typed in the browser is … Continue reading Getting started with gRPC – part II: the code
Getting started with gRPC – part I: the what
I recently spent some time researching gRPC and this post is a summary of what I learned. I also wrote a prototype application to test gRPC and gRPC-Web with Python and JS. The JS client takes a string from user input and test if it's a palindrome. The code can be found on GitHub and … Continue reading Getting started with gRPC – part I: the what
Do I need to indent my Python code? What about JavaScript?
Yes! Indentation, or leading white space at the beginning of a line is required in Python. You can read more about why that is important here. And here is the part of the style guide convention for indentation (PEP 8). In JavaScript on the other hand, white space is added for readability only but it … Continue reading Do I need to indent my Python code? What about JavaScript?
Difference among list, tuple and set in Python and when to use each one
Python has three similar data structures that can hold an unordered collection of elements: list, tuple and set. Here's how they differ: initialization list: using the built-in list() or the square brackets ([]): list1 = list() # creates an empty list list2 = [] # also creates an empty list list3 = ['a', 'b', 'c', … Continue reading Difference among list, tuple and set in Python and when to use each one
Add a filename in the command line when running a Python script
OR: Run a Python script with arguments You can add arguments to the command line when running python scripts by importing the sys module from Python's standard library and using its argv function. Some examples: A simple script that displays the user name: def main(): name = 'Frodo' print(f'Hello, {name}') if __name__ == "__main__": main() … Continue reading Add a filename in the command line when running a Python script
Display nested dictionary content sorted by key in Python
Given a nested dictionary like this: dog_breeds = { 'Labrador Retriever': {'life_span': 14, 'male_weight': '36 Kg', 'female_weight': '32 Kg'}, 'Beagle': {'life_span': 15, 'male_weight': '11 Kg', 'female_weight': '10 Kg'}, 'German Shepherd': {'life_span': 13, 'male_weight': '40 Kg', 'female_weight': '32 Kg'}, 'Jack Russell Terrier': {'life_span': 16, 'male_weight': '8 Kg', 'female_weight': '8 Kg'}, 'Rottweiler': {'life_span': 10, 'male_weight': '60 Kg', … Continue reading Display nested dictionary content sorted by key in Python