<?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 The Practical Engineer on Medium]]></title>
        <description><![CDATA[Stories by The Practical Engineer on Medium]]></description>
        <link>https://medium.com/@mukundshukla000?source=rss-12d4a2a06ca0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5oMc9PaBmusFpVR9jIBijA.jpeg</url>
            <title>Stories by The Practical Engineer on Medium</title>
            <link>https://medium.com/@mukundshukla000?source=rss-12d4a2a06ca0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:33:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mukundshukla000/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[The Hidden Engine Behind Python’s Syntax]]></title>
            <link>https://medium.com/@mukundshukla000/the-hidden-engine-behind-pythons-syntax-6f43f5342271?source=rss-12d4a2a06ca0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f43f5342271</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[dunder-method]]></category>
            <dc:creator><![CDATA[The Practical Engineer]]></dc:creator>
            <pubDate>Sun, 21 Jun 2026 18:48:59 GMT</pubDate>
            <atom:updated>2026-06-21T18:48:59.195Z</atom:updated>
            <content:encoded><![CDATA[<p>When people write like :</p><pre>len(store)<br>store[0]<br>for item in store:</pre><p>It looks like Python already has the built-in syntax present for these methods we are calling.</p><p>But internally, Python translates these operations into method calls on an object.</p><p>len(store) -&gt; store.__len__()</p><p>store[1] -&gt; store.__getitem__(1)</p><p>This design is known as the <strong>Python Design model.</strong></p><p>Let me take an example of java program:</p><p>List&lt;Integer&gt; newlist = new ArrayList&lt;&gt;();</p><p>here we can only use newlist.length() if the ArrayList class already have the length() method.. so it depends on the methods which are getting inherited. But, Python doesn’t care if our class inherits from a list or not.</p><h3>Sized Protocol (__len__)</h3><pre>def __len__(self) -&gt; int:<br>    return len(self._items)</pre><h3>Subscriptable Objects (__getitem__)</h3><pre>def __getitem__(<br>    self,<br>    index: int | slice<br>):<br><br># this will keep the slicing feature as well with the getitem </pre><h3>Mutable Containers (__setitem__)</h3><pre>def __setitem__(self, index, value):<br>    self._items[index] = value</pre><h3>Iteration Protocol:</h3><p>we know that below code works because of <strong>__iter__()</strong></p><pre>for item in store:</pre><p>The interpreter performs roughly</p><pre>iterator = store.__iter__()</pre><p>Then repeatedly:</p><pre>item = iterator.__next__()</pre><p>until StopIteration</p><h4>There are a couple more but the real lesson is to not remeber all the dunder methods… but, to know that python is fundamentally built on top of protocol-oriented design.</h4><h3>Iterable vs Iterator</h3><p><strong>Iterable </strong>is something that can produce an iterator.</p><p>for example: list, tuple, dict, set</p><p>All these are iterables</p><p>eg: num = [1,2,3]</p><p>iter(num)</p><p>this will return us &lt;list_iterator&gt; the list itself is not the iterator.</p><p>whereas <strong>Iterator </strong>is an object that remembers the state and produces values one at a time.</p><p><strong>Iterator </strong>must implement <strong>__iter__() and __next__()</strong></p><h3>Now, let&#39;s create a class that has its own iterator</h3><pre>class Counter:<br>  def __init__(self):<br>    self.current = 0<br>  def __iter__(self):<br>    return self<br>  def __next__(self):<br>    self.current+=1<br>    return self.current</pre><p>Now this kind of design can be dangerous because the iteration state is stored on the object itself. Multiple loops share state.</p><pre># lets say i created an object of counter class<br>counter = Counter()<br>for x in counter:<br>  ...<br>for y in counter:<br>  ...</pre><p>Here second loop will continue where the first loop stops… we need to make sure that we return a separate iterator object.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f43f5342271" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What actually happens when we run Python app.py?]]></title>
            <link>https://medium.com/@mukundshukla000/what-actually-happens-when-we-run-python-app-py-0bcee8963315?source=rss-12d4a2a06ca0------2</link>
            <guid isPermaLink="false">https://medium.com/p/0bcee8963315</guid>
            <category><![CDATA[cores]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[The Practical Engineer]]></dc:creator>
            <pubDate>Sun, 21 Jun 2026 13:26:03 GMT</pubDate>
            <atom:updated>2026-06-21T13:26:03.247Z</atom:updated>
            <content:encoded><![CDATA[<p>Here is what happens when you run your Python application with python app.py:</p><h3>Stage1: Source → Tokens</h3><p>In this step the CPython lexer reads the source file from left to right character by character. It creates a stream of tokens out of the program.</p><p>Tokens are words or single characters in the program like identifiers, keywords, single characters and special symbols or single characters for mathematical operations between two values.</p><h3>Stage 2: Tokens → Abstract Syntax Trees (ASTs)</h3><p>This step is performed by the parser for the CPython lexer and transforms the received tokens into an abstract syntax tree (AST) for the Python program, which is then used to represent the program’s structure as a tree.</p><h3>Stage 3: AST → Bytecode</h3><p>The code compiler for the CPython parser turns the parsed ASTs of the tokens into CPython bytecode for functions, methods and code blocks.</p><p>The CPython bytecode of a .py file is stored in a .pyc file inside the __pycache__ directory for the package of the .py file.</p><p>Each function, each method, each code block (even inside functions) is compiled into a stream of Bytecode Instructions which is then run by the PVM, e.g. LOAD_FAST.</p><h3>Stage 4: Bytecode → PVM Execution</h3><p>The Python Virtual Machine (PVM) or CPython’s core eval loop is what executes the bytecode.</p><p>This is where the core of Python’s functionality takes place.</p><p>In CPython, the PVM is a C-level eval loop that is essentially a massive switch in C that calls the correct C function for each bytecode op.</p><p>GIL Enforcement: There is a Global Interpreter Lock that means while one thread is running Python code then another thread cannot run Python code.</p><p>The lock is released during calls to IO system functions and during calls to C functions from native extensions (like NumPy and PyTorch) that release the GIL during CPU intensive operations.</p><p>Here is an example of how you would use python to view the bytecode of a function:</p><p>import dis</p><p>dis.dis(my_function)</p><p>When code is CPU-bound, the execution of the code can become slower as the code is interpreted line by line.</p><p>For production code that is CPU-bound the developer will typically need to use Cython, Numba or C code for the hot code paths in the application as well as use multiprocessing for the CPU parallelism.</p><p>Why This Works: This explains why you never seem to hit Python’s ceiling for CPU-bound work, and gives you the information to decide when to use Cython, Numba, C extensions, or even multiprocessing for your hot paths.</p><p><strong>Note</strong>: “Python 3.11” (Python 3.11’s interpreter has changed the specializing adaptive interpreter the PVM of CPython now learns from repeated executions of opcodes and for frequently hit bytecodes it now writes out type specialized faster versions of them.</p><p>How much of a speed up one gets on average is in the ballpark of 10–25% in terms of pure speed of Python execution).</p><blockquote>“__pycache__”: (Compiled .pyc files for Python in the directory where the .py files for that code are, typically named after the Python version running the code. No recompilation of .py files if the mtime and size have not changed for that file).</blockquote><blockquote>Note: The five steps described above form a highly simplified view of how Python code is being executed. As a rule, they don’t directly translate into machine code.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0bcee8963315" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>