<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nehemiah Kamolu on Medium]]></title>
        <description><![CDATA[Stories by Nehemiah Kamolu on Medium]]></description>
        <link>https://medium.com/@Nehe_Kamolu?source=rss-b99d8cebde09------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5LpEsMaplJtzt7l0oNItLw.jpeg</url>
            <title>Stories by Nehemiah Kamolu on Medium</title>
            <link>https://medium.com/@Nehe_Kamolu?source=rss-b99d8cebde09------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 03:46:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Nehe_Kamolu/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Amazon EC2 Basics for AI and Backend Engineers -Part 1]]></title>
            <link>https://medium.com/@Nehe_Kamolu/amazon-ec2-basics-for-ai-and-backend-engineers-71b14ff717f4?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/71b14ff717f4</guid>
            <category><![CDATA[aws-ec2]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Thu, 08 Oct 2026 14:03:15 GMT</pubDate>
            <atom:updated>2026-10-08T14:13:22.663Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CMdocjxHsAujTpvt" /><figcaption>Photo by <a href="https://unsplash.com/@querysprout?utm_source=medium&amp;utm_medium=referral">Marques Thomas</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>EC2 stands for Elastic Compute Cloud Amazon EC2 provides on-demand scalable computing capacity in the AWS cloud.</p><p>You make use of it by creating an EC2 instance. An EC2 instance is a virtual machine (VM) that runs in the cloud. Amazon EC2 offers over 500 unique instance types. You don’t need to memorize them. I’ll guide you.</p><p>You pick an instance depending on your storage, memory, networking, and operating system needs. When you launch an instance, you decide the virtual hardware configuration by choosing an instance.</p><p>The configuration also determines that of the physical hardware. Every instance type’s offerings, like compute, memory, and storage, are grouped into an instance family based on their capabilities.</p><p>To summarize the above before going deeper, know that</p><ul><li>An instance is a VM</li><li>An instance type is a collection of virtual hardware components like memory and CPU</li><li>Instance types are grouped into instance families.</li><li>Each family is meant to solve a specific use case. — Instance families have subfamilies. They’re grouped according to the processor and storage.</li><li>Instances use vCPU (Virtual Central Processing Unit), a measure of processing ability.</li><li>A vCPU represents one thread of the underlying physical CPU. — For example, if an instance has 2 CPU cores and two threads per core, it will have four vCPUs.</li></ul><p><strong>Amazon EC2 Instance Architectures</strong></p><p>The options provided are Intel, ARM (Graviton), and AMD processors. Here are examples of how they are named.</p><ul><li>Intel — c5, m5, r5</li><li>AMD — c5a, m5a, t3a</li><li>Graviton — c6g, m6g</li></ul><p>Different instances can have the same or different architectures. Depending on your cost and workload, you may find Graviton and AMD offer more benefits.</p><p><strong>Amazon EC2 Instance Generations</strong></p><p>Newer generations offer the following,</p><ul><li>Better price, performance, and security like the AWS Nitro system</li><li>Improved features</li><li>New features</li><li>Enhanced networking and throughput for storage (EBS)</li></ul><p>Multiple CPU generations can occur within a single instance generation.</p><p><strong>Instance Sizes</strong></p><p>Knowing the size allows you to make a decision based on your workload and objectives. The size is tied to the vCPU count.</p><p>Here are examples.</p><ul><li>C type instance — c5.2xlarge — 16 GiB memory &amp; 8 vCPU (2:1)</li><li>M type — m5.2xlarge — 32 GiB memory &amp; 8 vCPU (4:1)</li><li>R type — r5.2xlarge — 64 GiB memory &amp; 8 vCPU (8:1)</li></ul><p>Note that the memory ratios change by instance type.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71b14ff717f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Filter Hundreds of Files by Extension in Python]]></title>
            <link>https://medium.com/@Nehe_Kamolu/how-to-filter-and-copy-files-by-extension-in-python-332c7e439957?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/332c7e439957</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Mon, 12 Feb 2024 17:23:09 GMT</pubDate>
            <atom:updated>2024-02-12T17:24:49.937Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3t-rezTIvwlp51w2SbUmHg.png" /></figure><p>Have you ever needed to filter through a large directory of files and copy only the ones with a specific file extension to a new folder? Doing this manually could take hours, but with Python, you can automate the process in just a few lines of code.</p><p>In this article, I’ll show you how to write a Python script that filters through a directory of files and copies files with a specific file extension to a new directory.</p><p>We’ll start with a basic Python script that takes in two arguments—the source directory path and the destination directory path—and recursively searches the source directory for files with a specific file extension. Here is what the script looks like:</p><pre><br>import os<br>import shutil<br>import sys<br><br>if len(sys.argv) &lt;= 1:<br>  extension = &quot;.pdf&quot;<br>else:<br>  extension = sys.argv[1]<br><br>def filter_files(source_dir, destination_dir):<br>  if not os.path.exists(destination_dir):<br>    os.makedirs(destination_dir)<br>  for root, dirs, files in os.walk(source_dir):<br>    for file in files:<br>      if file.endswith(extension):<br>        file_path = os.path.join(root, file)<br>        dest_path = os.path.join(destination_dir, file)<br>         shutil.copy2(file_path, dest_path)<br><br>source_dir = &quot;/path/to/source/directory&quot;<br>destination_dir = &quot;/path/to/destination/directory&quot;<br><br>filter_files(source_dir, destination_dir)</pre><p>Let’s break down what is going on here. The script starts by importing the `os`, `shutil`, and `sys` modules, which we will need for directory traversal, file copying, and command-line argument parsing, respectively.</p><p>Next, we check for command-line arguments. If the user does not provide an argument, the script will default to filtering for `.pdf` files. If an argument is provided, we will use that instead.</p><p>The `filter_files` function takes in the `source_dir` and `destination_dir` arguments and first checks if the destination directory exists. If it does not, it creates the directory using `os.makedirs()`. The function then uses `os.walk()` to traverse the `source_dir` recursively and find all files in each subdirectory. For each file, if it has the specified file extension (`extension`), the function constructs the file and destination paths using `os.path.join()`, and then uses `shutil.copy2()` to copy the file to the destination directory.</p><p>To use this script for your own purposes, simply adjust the variables `source_dir` and `destination_dir` accordingly.<br>For example, on Mac OS, the `source_dir` can be set to `/Users/nehemiah/Desktop/Music_Files` and the `destination_dir` set to `/Users/nehemiah/Desktop/Filtered_Files`.</p><p>To run this script, navigate to the directory where you saved the script file in your terminal and run the command:</p><p>python filter_files.py</p><p>This will run the script with the default `.pdf` file extension. If you want to filter for a different file extension, run the command:</p><p>python filter_files.py .docx</p><p>This will filter for <strong>`.docx</strong>` files instead.</p><h3>Demo</h3><p>Below is a video on YouTube showing how I wrote the script.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fh2sTbLa2Eno%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dh2sTbLa2Eno&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fh2sTbLa2Eno%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bb3c561582bb8bc89626bd5e77c18ee/href">https://medium.com/media/5bb3c561582bb8bc89626bd5e77c18ee/href</a></iframe><p>In conclusion, by using just a few lines of Python code, you can automate the process of filtering and copying files by extension, saving you precious time and effort. With a little creativity, you can even modify this script to do more complex file filtering and copying.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=332c7e439957" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master Caching in Django: Boosting Performance with Cache]]></title>
            <link>https://medium.com/@Nehe_Kamolu/master-caching-in-django-boosting-performance-with-cache-1bb8b87bcdf5?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bb8b87bcdf5</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Tue, 04 Jul 2023 12:22:14 GMT</pubDate>
            <atom:updated>2023-07-04T12:22:14.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ineN0wRljkSbMtPA" /><figcaption>Photo by <a href="https://unsplash.com/@joshuaryanphoto?utm_source=medium&amp;utm_medium=referral">Joshua Reddekopp</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Caching plays a crucial role in web application performance, ensuring faster response times and reducing server load. With Django, developers have access to powerful caching mechanisms that can significantly enhance their applications. By intelligently caching data, templates, and database queries, you can minimize the need for redundant processing and database hits, resulting in improved performance.</p><p>In this article, we will explore how to harness the caching capabilities of Django, enabling you to optimize response times and deliver a seamless user experience while reducing the strain on your server resources. Let’s dive into the world of caching in Django!</p><h3>Enabling and Configuring Cache in Django</h3><p>To enable caching in Django, you need to configure cache-related settings in your project’s settings file. Django supports various cache backends, including in-memory options like Memcached or Redis, and file-based caching. With just a few lines of configuration, you can unleash the power of caching and optimize the performance of your application.</p><p>Your cache preferences go in the <strong>CACHES</strong> settings in your settings.py file. <strong>CACHES </strong>must configure a <strong>default</strong> cache. Any number of additional caches may also be specified. Below is an example of a cache configuration.</p><pre>CACHES = {<br>    &quot;default&quot;: {<br>        &quot;BACKEND&quot;: &quot;django.core.cache.backends.redis.RedisCache&quot;,<br>        &quot;LOCATION&quot;: &quot;redis://127.0.0.1:6379&quot;,<br>    }<br>}</pre><p><strong>Backend</strong>: The cache backend is Redis. This is done by setting the value to <em>django.core.cache.backends.redis.RedisCache .</em></p><p><strong>Location</strong>: This is the URL pointing to your REDIS instance. The url <em>redis://127.0.0.1:6379</em> means I have Redis running on my local machine on port <em>6379</em><strong><em>. </em></strong>If the Redis server you plan to use is protected and requires authentication configure your LOCATION<strong> </strong>as shown below.</p><pre>&quot;LOCATION&quot;: &quot;redis://&lt;username&gt;:&lt;password&gt;@&lt;server_address&gt;:&lt;port&gt;&quot;,</pre><p><a href="https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-CACHES">Click here</a> to find an explanation of all available values for <a href="https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-CACHES"><strong>CACHES</strong></a>.</p><h3>Template Fragment Caching</h3><p>Template fragment caching is a powerful technique in Django that allows you to cache specific sections of your templates. By caching these fragments, you can avoid repetitive rendering and improve the overall performance of your application.</p><p>To implement template fragment caching, you can use the <em>{% cache %}</em> template tag provided by Django. This tag allows you to specify the cache key, timeout, and dependencies for the cached fragment. <br>To use <em>{% cache %}</em>, put <em>{% load cache %}</em> near the top of your template. The <em>{% cache %}</em> template tag takes two arguments, the timeout in milliseconds and the fragment’s cache name. If the timeout is None, the fragment is cached forever. You can pass dynamic data to the cache tag by passing one or more additional arguments.</p><p>Consider a scenario where you have a complex and computationally expensive template fragment that displays a list of recent blog posts. By wrapping this fragment with {% cache %} and providing a cache key based on the current user and the latest blog post timestamp, you can cache the rendered output and serve it directly from the cache for subsequent requests. Look at the example below.</p><pre>% load cache %}<br><br>{% cache 1000 blog_cache request.user.email timestamp %}<br>    ...<br>{% endcache %}</pre><p>In the above snippet, the timeout is 1000ms , the cache key is blog_cache, followed by two additional arguments the user’s email and a timestamp.</p><h3>Per View Caching</h3><p>This technique is used to cache the output of individual views. To cache the result of a view, use the @cache_page decorator. It takes one argument, the cache timeout in seconds. You can also pass additional keyword arguments like <em>cache=&quot;special_view_cache&quot;</em> and this will tell the decorator to use the cache <em>special_view_cache</em> from your <strong>CACHES</strong> setting. Look at the code below.</p><pre>from django.views.decorators.cache import cache_page<br><br><br>@cache_page(900, cache=&quot;special_view_cache&quot;)<br>def my_view(request):<br>  ...</pre><p>Find more details about per-view caching <a href="https://docs.djangoproject.com/en/4.2/topics/cache/#template-fragment-caching">here</a>.</p><h3>Per Site Cache</h3><p>You can cache your entire site by adding <strong>&#39;</strong>django<strong>.</strong>middleware<strong>.</strong>cache<strong>.</strong>UpdateCacheMiddleware<strong>&#39;</strong> and <strong>&#39;</strong>django<strong>.</strong>middleware<strong>.</strong>cache<strong>.</strong>FetchFromCacheMiddleware<strong>&#39;</strong> to your <a href="https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-MIDDLEWARE"><strong>MIDDLEWARE</strong></a> setting, as shown the snippet below.</p><pre>MIDDLEWARE = [<br>    &quot;django.middleware.cache.UpdateCacheMiddleware&quot;,<br>    &quot;django.middleware.common.CommonMiddleware&quot;,<br>    &quot;django.middleware.cache.FetchFromCacheMiddleware&quot;,<br>]</pre><p>The update middleware must be the first and the fetch middleware last. Read more about per site cache<a href="https://docs.djangoproject.com/en/4.2/topics/cache/#the-per-site-cache"> here.</a></p><h3>Low Level API Cache</h3><p>Sometimes caching the entire output of your view may be overkill for your app and you just want to cache specific expensive computational results. This is where the low-level caching api can be useful. Consider the code below.</p><pre>&gt;&gt;&gt; from django.core.cache import caches<br>&gt;&gt;&gt; cache = caches[&#39;my_cache_alias&#39;]</pre><p>If the named key does not exist, an <strong>InvalidCacheBackendError</strong> will be raised.</p><p>The default cache is available as <strong>django.core.cache.cache</strong>. It’s the same as caches[‘default’].</p><p>You can add and retrieve data from your cache as shown below.</p><pre>&gt;&gt;&gt; cache.set(&#39;my_key&#39;, &#39;hello, world!&#39;, 30)<br>&gt;&gt;&gt; cache.get(&#39;my_key&#39;)<br>&#39;hello, world!&#39;<br><br>or<br><br>&gt;&gt;&gt; cache.get_or_set(&quot;my_new_key&quot;, &quot;my new value&quot;, 100)</pre><p>Cache.set() takes 2 arguments, the cache key, the cache value, and the timeout. For more details on the low-level API, click <a href="https://docs.djangoproject.com/en/4.2/topics/cache/#the-low-level-cache-api">here</a>.</p><h3>Cache Invalidation</h3><p>Cache invalidation is a critical aspect of caching. It ensures that cached data remains consistent with the latest updates, preventing users from accessing outdated or stale information. Django provides several strategies for cache invalidation that you can employ based on your application’s requirements.</p><p>You can use cache<strong>.</strong>delete(key) to invalidate a <a href="https://docs.djangoproject.com/en/4.2/topics/cache/#django.core.cache.utils.make_template_fragment_key">template fragment</a>, cache<strong>.</strong>delete_many([“key_1”, “key_2”, “key_3”]) for multiple keys, cache.clear() and timeouts. <strong>cache.clear() </strong>will remove everything from the cache and not only the keys set by your app.</p><h4>Summing Up</h4><p>We explored caching techniques available in Django, including template fragment caching, per-view caching, entire site caching, explored the low-level cache api, and cache invalidation.</p><p>For more details on the Django Cache Framework and concepts like Cache key prefixing, downstream caches, asynchronous support, and cache versioning, among others visit the official docs using this <a href="https://docs.djangoproject.com/en/4.2/topics/cache/">link</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bb8b87bcdf5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Built a Web Application Using Django and Next.Js]]></title>
            <link>https://blog.devgenius.io/i-built-a-web-application-using-django-and-next-js-fd964260203f?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd964260203f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Wed, 23 Mar 2022 06:15:45 GMT</pubDate>
            <atom:updated>2022-03-24T22:04:19.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="A screenshot of a portion of LiveUp’s landing page" src="https://cdn-images-1.medium.com/max/1024/1*vCZQc3Znv6nPQcWehQJDEA.png" /><figcaption>A screenshot of a portion of LiveUp’s landing page</figcaption></figure><p>LiveUp enables doctors to track patient prescriptions, reduce redundancies and manual processes.</p><h3>Inspiration</h3><p>At a dispensary in my town, there are long processes and repetitive steps. One day, I was asked to provide information about past medications I received but could not produce or remember specifics. The book that the health worker had written in was destroyed by rain.</p><p>I also noticed some patients carried more than one book to every office they entered. If one or all got misplaced or destroyed, a lot of information can be lost. This would require the health worker to record the details a second or N times.</p><h3>Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68fXMInNRmP6QEGF6i87MA.png" /><figcaption>Architectural illustration of LiveUp sysem</figcaption></figure><p>The web app is hosted on <a href="https://vercel.com/"><strong>Vercel</strong></a>, a perfect place to host a Next.Js application. It then consumes the REST API hosted on <a href="https://www.heroku.com/"><strong>Heroku</strong></a>. The setup on Heroku includes a PostgreSQL database used by the API.</p><h3>Tools and technologies used</h3><ul><li>For the Frontend, I chose to use <a href="https://nextjs.org/"><strong>Next.Js</strong></a>, ( involving <strong>HTML</strong>, <strong>CSS</strong>, <strong>React-Bootstrap</strong>, and J<strong>avascript</strong>) because it has a simple file-based routing system, there’s no need to set up React-Router, automatic code-splitting, pre-rendering, route prefetching, inbuilt image optimization component, use of CDNs in production, API routes, incremental static page generation, typescript support, among others.</li><li>I built the API using <a href="https://www.djangoproject.com/"><strong>Django</strong></a>. Django ships with an admin panel that covers common CRUD admin tasks. This reduced the amount of time required to build a custom admin. The Django ORM excites me the most, very powerful and yet way too intuitive. It’s indeed the framework for perfectionists with deadlines.</li></ul><figure><img alt="Screenshot of LiveUp’s Django Admin Panel" src="https://cdn-images-1.medium.com/max/1024/1*c7BAL-SZ15x3kBJYkzcd0w.png" /><figcaption>Screenshot of LiveUp’s Django Admin Panel</figcaption></figure><ul><li><a href="https://www.postgresql.org/"><strong>PostgreSQL</strong></a>. This is a favorite in the python community. Very easy to set up in the Django settings.py file and let the migrations do the talking for you.</li><li><a href="https://vercel.com/"><strong>Vercel</strong></a>. It is built by the Next.Js team for hosting Next apps. The most interesting feature is the preview links generated for your development Git branches that you can share with your team before pushing to main.</li><li><a href="https://www.heroku.com/"><strong>Heroku</strong></a>. A common cloud solution that I’ve used to host ExpressJs APIs in the past. I set up both the API and database on Heroku.</li><li><a href="https://git-scm.com/"><strong>Git </strong></a>&amp; <a href="https://github.com/"><strong>Github </strong></a>for version control and easy deployment.</li><li><a href="https://www.docker.com/"><strong>Docker </strong></a>to avoid the excuse of “It works on my machine”.</li></ul><h3>Features</h3><h4>All users</h4><ul><li>Log in and logout</li><li>Edit profile.</li><li>Generate PDFs and CSVs.</li><li>Filtering, sorting, and pagination.</li></ul><h4>Admin</h4><ul><li>An admin can add a ward, register a receptionist and health workers, and can alter their data. A health worker is either a doctor, nurse, or student clinician.</li></ul><h4>Receptionists</h4><ul><li>A receptionist can register a patient and view only patients they have registered</li><li>Can refer a patient to a health worker.</li><li>View referral history of a patient made by all receptionists.</li><li>Edit only a referral they made.</li><li>Can modify and view a patient’s details.</li><li>Can view the number of patients they have registered and referred for the current day, and since the registration started.</li><li>Can view the number of patients registered and referred by all receptionists for the current day, and since the registration started.</li></ul><figure><img alt="A screenshot of a modal used by a receptionist to refer a patient to a health worker" src="https://cdn-images-1.medium.com/max/1024/1*MqZXlA8dz7gBnT-gCaYsFA.png" /><figcaption>A screenshot of a modal used by a receptionist to refer a patient to a health worker</figcaption></figure><h4>Health workers</h4><ul><li>Can view all patients assigned to them.</li><li>Admit and prescribe medication.</li><li>View patient past admissions and prescriptions made by all health workers.</li><li>Can edit an admission or prescription they made.</li><li>Can view the number of patients referred, admitted, prescriptions made, by all health workers for the current day, and the total from the first referral.</li><li>Can view the number of patients they have referred, admitted, prescriptions made, for the current day, and the total from the first referral.</li></ul><figure><img alt="A screenshot of a modal with a form that a doctor can use to record a prescription for a particular patient" src="https://cdn-images-1.medium.com/max/1024/1*-lTNykULjodfnM1oDF0_fw.png" /><figcaption>A screenshot of a modal with a form that a doctor can use to record a prescription for a particular patient</figcaption></figure><h3>Challenges</h3><ul><li>I faced race conditions when managing the state. At some point, when I was creating a feature to enable clinicians to update a prescription. Part of the application state was being changed without my intent. I learned that before one action was complete, another had already changed the value and hence unexpected results. It forced me to undo a lot of work to track it down. I added plenty of logs in every function to follow the entire flow. I also used the developer tools in Google Chrome to identify bugs.</li><li>I discovered I was using the <a href="https://github.com/Tivix/django-rest-auth/issues/568">no longer </a>supported d<a href="https://github.com/Tivix/django-rest-auth">jango-rest-auth package</a> for JSON Web Token. This was after 3 days of implementing authentication and authorization. I had to refactor the affected code and get familiar with its replacement, <a href="https://github.com/iMerica/dj-rest-auth">dj-rest-auth</a>.</li><li>Re-learning <a href="https://react-bootstrap.github.io/">React Bootstrap</a>. I forgot most of the Bootstrap classes. I had to remind myself of the basics.</li></ul><h3>What I Learnt</h3><p>This isn’t the first time building a project using either Django or Next.Js. Most of it was a revision and mastery experience. However, I learned the following,</p><ul><li>How to set up a Django project and PostgreSQL DB on Heroku.</li><li>Nested serializers in Django Rest Framework.</li><li>How to use <a href="https://github.com/iMerica/dj-rest-auth"><strong><em>Dj-rest-auth</em></strong></a><strong><em> </em></strong>package. It ships with routes for getting tokens, email and password reset, out of the box.</li><li><a href="https://redux-toolkit.js.org/"><strong>Redux Toolkit</strong></a> for state management in the Frontend.</li><li>More React-Bootstrap components and classes.</li><li>Docker, docker files, and docker-compose. I intend to go more into Docker this year.</li></ul><h3>Links</h3><h4>Code</h4><ul><li><a href="https://github.com/KNehe/liveup_web">Frontend</a>, <a href="https://github.com/knehe/liveup_api/">Backend</a>.</li></ul><h4>Live Project</h4><p>I do not know how long the projects will be up because I used free hosting plans.</p><ul><li>Visit the <a href="https://liveup-web.vercel.app/">Frontend</a>.</li><li>Read <a href="https://nehe-liveup-api.herokuapp.com/api/v1/swagger/">Swagger docs</a>, <a href="https://nehe-liveup-api.herokuapp.com/api/v1/redoc/">Redoc docs</a>, or the <a href="https://nehe-liveup-api.herokuapp.com/api/v1/">browsable API</a>.</li></ul><h4>Demo</h4><p>Below is a video demonstrating the main features.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFrIVVXfFy-M%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFrIVVXfFy-M&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFrIVVXfFy-M%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/05e281399ebabcefb3c7cb495f9997e8/href">https://medium.com/media/05e281399ebabcefb3c7cb495f9997e8/href</a></iframe><p>Thank you for reading!!!😊😊.</p><p>Let’s connect on <a href="https://www.linkedin.com/in/nehemiah-kamolu/">LinkedIn</a> and <a href="https://twitter.com/Nehemiah_Nehe">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd964260203f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/i-built-a-web-application-using-django-and-next-js-fd964260203f">I Built a Web Application Using Django and Next.Js</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[6 Ways You Can Get Keys From a Python Dictionary]]></title>
            <link>https://blog.devgenius.io/6-ways-you-can-get-keys-from-a-python-dictionary-9487c57a16bf?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/9487c57a16bf</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Fri, 11 Mar 2022 14:08:49 GMT</pubDate>
            <atom:updated>2024-02-26T14:50:46.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M-UZTVI9XHiJyG1J" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A great developer will always try to insert and retrieve data in constant time (O(1)) if possible when creating algorithms. Dictionaries, also known as hash maps in some programming languages, can help us achieve such efficiency. We’ll not focus on Big Oh but on how we can retrieve keys in a Python dictionary. Keys can help us insert and retrieve data from a dictionary in constant time, at least almost always (except in situations of <a href="https://en.wikipedia.org/wiki/Hash_collision">collisions</a>, which can be rare).</p><p>We shall refer to the following dictionary data structure for every case below:. It stores people and their marks.</p><pre>dictionary = {&quot;Doe: 90, &quot;John&quot;: 95}</pre><h4><strong>1. Using a for loop and keys() dictionary method</strong></h4><p>The keys() method gives us an iterable we can loop through</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5ff6c00d4ee22b686040a63d18e6eb07/href">https://medium.com/media/5ff6c00d4ee22b686040a63d18e6eb07/href</a></iframe><p>To access a value, use the syntaxvalue = dictionary[key]. This returns a <strong>KeyError</strong> if the key is not found.</p><p>The safest approach is to use the get() dictionary method, whose prototype isget(key, default_value). Thedefault_value parameter is optional. If given, it is returned when the key is not found. When a key doesn’t exist and no default value is given explicitly, it Noneis returned as the default value.</p><h4><strong>2. Using inbuilt list() python method</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72144690bf13072f5a5c26307c29c6e0/href">https://medium.com/media/72144690bf13072f5a5c26307c29c6e0/href</a></iframe><p>Thelist() method provides a simple list of keys without using the keys() dictionary method. It is my favorite because of its readability.</p><h4><strong>3. Using list comprehension</strong></h4><p>We can get keys from a dictionary using list comprehension in two ways.</p><p>First, we can use thekeys()method mentioned above in point 1.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0d42eb6844092f2c14550825de3660c/href">https://medium.com/media/d0d42eb6844092f2c14550825de3660c/href</a></iframe><p>The second approach is without using the keys() method which looks shorter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29cdcf5972a7ad2f56d0e9ed3bfff3e4/href">https://medium.com/media/29cdcf5972a7ad2f56d0e9ed3bfff3e4/href</a></iframe><h4>4. Unpacking</h4><p>Unpacking refers to assigning the the values of an iterable to a variable(s) within a single statement.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b053b0ef792cd2a0c702746a0c44e6d/href">https://medium.com/media/4b053b0ef792cd2a0c702746a0c44e6d/href</a></iframe><p>The asterisk (*)helps us unpack the dictionary’s keys into the variablemy_keys.</p><h4><strong>5. Using a for loop without </strong><strong>keys() dictionary method</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2ef2cac37cfc261267b57c18a1ce33c/href">https://medium.com/media/c2ef2cac37cfc261267b57c18a1ce33c/href</a></iframe><h4><strong>6. Using items() dictionary method and a for loop</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff28e6355607da9efbe51aba1c8448ec/href">https://medium.com/media/ff28e6355607da9efbe51aba1c8448ec/href</a></iframe><p>Theitems()method returns a <em>dict_items</em> object containing keys and their values. Each key and value are stored in a tuple pair. We can can then unpack the key and value while iterating,, as shown in the snippet above.</p><p><strong>Note</strong>: I used Python 3.9.6 to implement all the the examples.</p><p>Here’s a brief video about the above, if you like</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoySoPOTZjyk%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoySoPOTZjyk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FoySoPOTZjyk%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b701dfe8c692e4e476630f9d4da6220/href">https://medium.com/media/1b701dfe8c692e4e476630f9d4da6220/href</a></iframe><p>Thank you for reading. Happy coding! 😊😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9487c57a16bf" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/6-ways-you-can-get-keys-from-a-python-dictionary-9487c57a16bf">6 Ways You Can Get Keys From a Python Dictionary</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type https://www.google.com in your browser and press Enter]]></title>
            <link>https://medium.com/@Nehe_Kamolu/what-happens-when-you-type-https-www-google-com-in-your-browser-and-press-enter-7df407af73ba?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/7df407af73ba</guid>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[http-request]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Sun, 23 Jan 2022 19:58:07 GMT</pubDate>
            <atom:updated>2022-01-23T19:59:20.145Z</atom:updated>
            <content:encoded><![CDATA[<h3>What happens when you type https://www.google.com in your browser and press enter</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mxxLraAkbQ8nwuz5" /><figcaption>Photo by <a href="https://unsplash.com/@nathanareboucas?utm_source=medium&amp;utm_medium=referral">Nathana Rebouças</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Important terms</h3><p>Let’s understand the following terms before getting into details.</p><p><strong>Internet</strong></p><p>A global connection of computers used to share resources and information.</p><p><strong>ISP</strong></p><p>An Internet Service Provider(ISP) is an organization that provides you with the service of accessing the internet.</p><p><strong>Browser</strong></p><p>Application software used to access the <em>World Wide Web</em> (www) e.g Chrome, Firefox, Safari, etc. www is simply a public collection of hyperlinked webpages on the internet.</p><p><strong>Port</strong></p><p>A port is a communication channel</p><p><strong>Protocol</strong></p><p>A set of rules which determine how data is transmitted between devices</p><p><strong>TCP/IP and UDP</strong></p><p>Communication among network devices on the internet follows a certain suite of rules or protocols. One of them is Transmission Control Protocol/ Internet Protocol (TCP/IP) where a message is split into packets. TCP ensures no packets are missing and all are sent to the recipient. The alternative is User Data Protocol (UDP)which is used for fast communication, packets can be lost and the sender is unable to know if a packet was received. An application is video playback which is time-sensitive.</p><p><strong>HTTP and HTTPS</strong></p><p>Hypertext Transfer Protocol(HTTP) is a protocol that runs over TCP intending to make browsers and servers understand each other i.e it is the language your browser uses to ‘speak’ with a server. Hypertext Transfer Protocol Secure(HTTPS) is a secure version of HTTP where communication is encrypted so that when an attacker gets your message it can’t be understood.</p><p><strong>SSL/TLS</strong></p><p>Secure Sockets Layer(SSL) is an encryption protocol. Transport Layer Security (TLS) serves the same purpose as SSL to encrypt communication. It is modern and SSL is getting deprecated. HTTPS uses SSL/TLS to deliver encrypted data.</p><p><strong>IP address and Domain Name</strong></p><p>An Internet Protocol Address (IP address) is a unique address that identifies a device on a network. An example is <strong>8.8.8.8 </strong>(Google’s IP address). Since it is had to remember addresses, domain names were introduced. A domain name is a name of a website or device on a network e.g <strong>google.com.</strong></p><p><strong>DNS</strong></p><p>Domain Name System(DNS) is commonly referred to as the Internet’s Phone Book. Every domain name is stored with its corresponding IP address.</p><p><strong>Server</strong></p><p>A computer that provides resources to other computers.</p><p><strong>Load Balancer</strong></p><p>A system that evenly distributes traffic from clients to servers.</p><p><strong>Firewall</strong></p><p>A firewall is a device or software used to monitor and filter incoming and outgoing requests.</p><p><strong>Database</strong></p><p>It is a collection of information that is stored and organized so that it can be easily accessed, updated, and managed.</p><p><strong>Cache</strong></p><p>A cache is data stored on a device so that it can easily be accessed in the future. The goal is to avoid requesting the same data which never changes.</p><p><strong>URL</strong></p><p>A Uniform Resource Locator is an address that specifies the location of a resource on a network. An example is https://medium.com where https is the protocol, medium.com is the domain, .comis the top-level domain. The URL can also be written as http:80//www.example.com/path_to_page where 80 is the port(default for HTTP), www to distinguish content but is usually left out, and the path path_to_page, that points to a specific resource, comes after the domain.</p><p><strong>HTML, CSS, JavaScript.</strong></p><p>They are technologies used to create websites. HTML defines the structure and semantics, <a href="https://developer.mozilla.org/en-US/docs/Learn/CSS">CSS</a>enhances the look, and <a href="https://developer.mozilla.org/en-US/docs/Learn/JavaScript">JavaScript</a>is used to provide interaction.</p><h3>Getting started</h3><h3>Typing</h3><p>When you type https://www.google.com or any other URL and hit enter, the browser checks its cache if that resource exists. If it doesn’t, ask the operating system(OS), which checks the host file for the same resource. When non-existent in the OS, the request moves to your ISP through your internet connection to check if it has it in its cache. If the cache or operating system has the data, the browser then uses the data to pick the destination’s IP address (Google&#39;s). In our case, we assume you have never searched google.com before and the protocol to be established is HTTPS operating on port 443.</p><h4>DNS, TCP, and SSL</h4><p>The request is then sent to DNS servers to get the IP address of google.com. The browser then uses it to make first contact with the Google server.</p><p>A TCP connection is established between the two entities. In simple terms, a means of transport has been created for the browser to move data to the server.</p><p>The server then sends an SSL certificate to your browser. This certificate has a public key that will be used to establish a uniquely secure connection. This leads to an SSL handshake that involves the creation of shared secrets. On success, you will see a padlock icon in your browser.</p><p>Some server setups use an Extended Validation Certificate in place of an SSL certificate. With this, your address bar will turn green.</p><p>The browser then organizes your URL, includes it in a special message format, and sends an HTTP request to the server. Below is an example of an HTTP request.</p><pre>Get /google.com/ HTTP/1.1<br>User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)<br>Host: www.example.com<br>Accept-Language: en-us<br>Accept-Encoding: gzip, deflate<br>Connection: Keep-Alive</pre><pre>Body</pre><p>The first line is the start line, followed by headers, a blank line, and an optional body. To learn more about HTTP requests in detail read <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages">this MDN article</a>.</p><h3>Load balancing</h3><p>You are not the only one making requests for the same site. Hundreds if not thousands of requests are made. The address returned by the DNS server is that of a server configured with a load balancer. The load balancer then determines which server to send your request to. If you make 10 requests, your responses may come from 10 different servers. A load balancer distributes each request to 10 healthy servers. On a higher level of design, more than one load balancer is used. This means incoming requests are shared between the many load balancers before each makes the distribution.</p><h3>Firewalls</h3><p>Every load balancer has a firewall to filter your request. For example, if you requested sensual content in some setups, the request is terminated. When a response is retrieved, the firewall can prevent it from being sent to you in other setups.</p><h3>Types of servers involved</h3><p>When your request wasn’t blocked by the firewall and has been sent through the load balancer to the appropriate server. Your request can be served by either an<strong> application</strong> <strong>server</strong> or <strong>web server. </strong>An application server is responsible for providing dynamic content. This is usually done by fetching new records from the database and updating the response. Web servers provide static content typically HTML, CSS, and images.</p><h3><strong>Back to the browser</strong></h3><p>The server returns an HTTP response which is interpreted by your browser. It can send the response back to your browser because it knows your IP address.</p><p>The browser first parses the HTML and looks for &lt;<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link">link</a>&gt; and &lt;<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script">script</a>&gt;tags which reference CSS and JavaScript files respectively.</p><p>As it parses, the browser sends back a request for the CSS and JavaScript files according to the &lt;<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link">link</a>&gt; and &lt;<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script">script</a>&gt; tags found, then parses the CSS and JavaScript.</p><p>It then generates two trees. The <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model">DOM </a>tree from parsed HTML and <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSSOM">CSSOM</a> from parsed CSS executes the JavaScript after compilation.</p><p>As your browser parses the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model">DOM </a>tree, applies styles from the <a href="https://developer.mozilla.org/en-US/docs/Glossary/CSSOM">CSSOM</a>tree, and executes JavaScript, the screen is painted and then you see a full webpage that you can interact with. An example of an HTTP response is shown below.</p><pre>HTTP/1.1 200 OK<br>Access-Control-Allow-Origin: *<br>Connection: Keep-Alive<br>Content-Encoding: gzip<br>Content-Type: text/html; charset=utf-8<br>Server: Apache<br>Set-Cookie: csrf_token=...</pre><pre>(Body)</pre><p>The HTTP response contains details such as the HTTP version, status code (on the first line), headers, and the body. To learn more about HTTP responses in detail visit <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Messages">this MDN article</a>.</p><p>Thank you for reading. Happy Googling! 😊😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7df407af73ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Pythonic Way of Implementing Encapsulation]]></title>
            <link>https://blog.devgenius.io/the-pythonic-way-of-implementing-encapsulation-d9426e7cf5d9?source=rss-b99d8cebde09------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9426e7cf5d9</guid>
            <category><![CDATA[objectorientedprogramming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[encapsulation]]></category>
            <dc:creator><![CDATA[Nehemiah Kamolu]]></dc:creator>
            <pubDate>Mon, 13 Dec 2021 06:39:31 GMT</pubDate>
            <atom:updated>2021-12-15T08:29:19.368Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EiTOFnwdCBZXPwtv" /><figcaption>Photo by <a href="https://unsplash.com/@synkevych?utm_source=medium&amp;utm_medium=referral">Roman Synkevych</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Introduction</h4><p>Encapsulation is the concept of wrapping variables and methods into a single unit. It is one of the pillars of Object-Oriented Programming(OOP). The goal is to ensure your data can be trusted. To earn trust, software developers create <em>private </em>variables, including <em>getter </em>and <em>setter </em>methods. A <em>getter </em>returns a value while a <em>setter </em>updates or sets a value.</p><h4>Let’s Dive In</h4><p>Below is a way you can think of implementing encapsulation in Python.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90c592200e7307a7f2e6ff0f3eaaf1a5/href">https://medium.com/media/90c592200e7307a7f2e6ff0f3eaaf1a5/href</a></iframe><p>In the code below, we create an object of the Person class above and attempt to use the variable name, which doesn’t give us any peace because a private variable can’t be accessed from the person object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ed2c7a0e2f14bd0dbc58ccb63bef40c/href">https://medium.com/media/2ed2c7a0e2f14bd0dbc58ccb63bef40c/href</a></iframe><p>To access it, you have to use the get_name() method. The same applies when setting its value. We must use the set_name(self, name) method.</p><p>What if I told you that the pythonic way of implementing encapsulation is by making everything public first! and not declaring variables private. I’m confident Java developers are sprinting for my throat. Throwing questions at me like how can you achieve encapsulation without private variables? Relax! Please keep reading. Look at the python code below. This is the first step towards achieving encapsulation in a pythonic way.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/57a959a1e13e3dbfad8a26d51feeda9c/href">https://medium.com/media/57a959a1e13e3dbfad8a26d51feeda9c/href</a></iframe><p>The variable name is not private anymore. Meaning the code below that caused an error earlier will work.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3fae904712b6f625ce7e596c3d7e8065/href">https://medium.com/media/3fae904712b6f625ce7e596c3d7e8065/href</a></iframe><p>I know you must be asking what if we want to hide data in the future, won’t this break the interface accessed by users of this class? <br>Trying to make the variablenameprivate in the future will break the code because it can no longer be accessed from the outside world.<br>How can we prevent such a problem and ensure data can be trusted through getters and setters?</p><p>Python has a happy solution for our concern using <strong><em>properties</em></strong>. Properties are interfaces to instance attributes. They encapsulate instance attributes just like getters and setters in other object-oriented languages like Java. Below is an example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7ba4f0dac3861888433f15d06353db0/href">https://medium.com/media/f7ba4f0dac3861888433f15d06353db0/href</a></iframe><p>Properties are created using the property decorator for the getter and the same name is used to create the setter. With this, you can apply rules when setting the name. An example, as shown below, would be changing the setter method to validate the value before setting it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fe153833309f7cbeadcc5d962fa7f42e/href">https://medium.com/media/fe153833309f7cbeadcc5d962fa7f42e/href</a></iframe><p>Accessing or changing the name through an object will be very possible. The code below will be happy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e34a626cc743bd40ed58dd57c835e7c8/href">https://medium.com/media/e34a626cc743bd40ed58dd57c835e7c8/href</a></iframe><p>If you try to set the name like so person.name = “ab”, it will fail because of the checks in the setter method.</p><p>Notice the interface hasn’t broken. If you make the variable name public first, then make it private later without using properties, the interface breaks (because a person.name will fail) and all users of the Person class has to refactor their code. This can cause problems when dealing with thousands of lines of code. Facing such an issue in other OOP languages like Java is very frustrating. It forces you to make all variables private at the start of the project even when not necessary. In Python, you can make them public first and if data protection and hiding are required later, you implement properties without users of the class changing their implementation. The variable name remained `public` yet its value can be trusted. You can’t change it without obeying the rules.</p><h4>Conclusion</h4><p>With that said, I have nothing against Java (actually my first love). I hope you find Python as fascinating as I do.<br>Happy encapsulating !!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9426e7cf5d9" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/the-pythonic-way-of-implementing-encapsulation-d9426e7cf5d9">The Pythonic Way of Implementing Encapsulation</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>