<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Docs-n-Notes Blog</title>
        <link>https://docs.tanthanh.dev/vi/blog</link>
        <description>Docs-n-Notes Blog</description>
        <lastBuildDate>Sat, 05 Aug 2023 00:00:00 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>vi</language>
        <item>
            <title><![CDATA[Model-Driven Programmability]]></title>
            <link>https://docs.tanthanh.dev/vi/blog/network-automation/model-driven-programmability</link>
            <guid>https://docs.tanthanh.dev/vi/blog/network-automation/model-driven-programmability</guid>
            <pubDate>Sat, 05 Aug 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[An introduction to model-driven programmability for network automation, covering standardized data models and their role in modern network management.]]></description>
            <content:encoded><![CDATA[<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="introduction">Introduction<a href="https://docs.tanthanh.dev/vi/blog/network-automation/model-driven-programmability#introduction" class="hash-link" aria-label="Đường dẫn trực tiếp đến Introduction" title="Đường dẫn trực tiếp đến Introduction" translate="no">​</a></h2>
<p>As network automation becomes more and more important, it's important to be familiar with the key concepts involved. One of the most important concepts is model-driven programmability.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="what-is-model-driven-programmability">What is model-driven programmability?<a href="https://docs.tanthanh.dev/vi/blog/network-automation/model-driven-programmability#what-is-model-driven-programmability" class="hash-link" aria-label="Đường dẫn trực tiếp đến What is model-driven programmability?" title="Đường dẫn trực tiếp đến What is model-driven programmability?" translate="no">​</a></h2>
<p>Model-driven programmability is a way of representing network devices and their capabilities in a standardized way. This makes it easier to automate tasks on network devices, as we can use a single model to represent all of the devices in wer network.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="why-is-model-driven-programmability-important">Why is model-driven programmability important?<a href="https://docs.tanthanh.dev/vi/blog/network-automation/model-driven-programmability#why-is-model-driven-programmability-important" class="hash-link" aria-label="Đường dẫn trực tiếp đến Why is model-driven programmability important?" title="Đường dẫn trực tiếp đến Why is model-driven programmability important?" translate="no">​</a></h2>
<p>Traditionally, network devices have been managed using a CLI (command-line interface). This approach is not very well-suited for automation, as it's difficult to extract information from the unstructured text output of the CLI.</p>
<p>Model-driven programmability solves this problem by providing a standardized way to represent network devices and their capabilities. This makes it easier to write automation scripts that can interact with network devices in a consistent way.</p>
<p>Data models describe the syntax and semantics of working with specific data objects. They answer questions such as:</p>
<ul>
<li class="">How is a VLAN object structured? What properties does it have?</li>
<li class="">What is the range of a valid VLAN ID?</li>
<li class="">Can a VLAN name have spaces in it?</li>
<li class="">Is the value a string or an integer?</li>
</ul>
<p>A data model is like a standardized framework used to describe a data object of an environment. The thought behind the data model is to provide a consistent and reliable format to communicate the data objects we are working with on wer device.</p>
<p>One misconception is that data models handle the exchange of data, which is not the case. Data models are just standardized frameworks that describe wer environment. Data models have nothing to do with data transmission. Instead, protocols such as Network Configuration Protocol (NETCONF) and RESTCONF send structured data (e.g., XML or JSON) encoded documents using a framework a given model governs.</p>
<p>As models focus on what is the content and not so much on how it is exchanged, data models allow the API to do the following:</p>
<ul>
<li class="">Provide efficient and easy-to-use tooling to consume it (programming libraries).</li>
<li class="">Support extensible and open interfaces (REST-based, NETCONF, and so on).</li>
<li class="">Add flexibility and support for different encoding formats (XML and JSON).</li>
<li class="">Support different types of transport (SSH, HTTPS, HTTP/2, etc.).</li>
</ul>
<p>Now that we understand a little more about model-driven programmability, it can be taken a step further and discuss how model-driven programmability fits into the larger concepts of APIs and network programmability.</p>
<p>The core structure of a device API, therefore, consists of the following:</p>
<ul>
<li class=""><strong>Data models</strong>: The foundation of the API consists of data models. Data models define the syntax and semantics, including constraints of working with the API. YANG is a data model used by NETCONF, RESTCONF, and gRPC.</li>
<li class=""><strong>Transport</strong>: Model-driven APIs support several transport methods, including SSH, TLS, and HTTP or HTTPS.</li>
<li class=""><strong>Encoding</strong>: Model-driven APIs support the choice of encoding, including XML and JSON, and custom encodings such as Google protocol buffers.</li>
<li class=""><strong>Protocols</strong>: Model-driven APIs also support multiple options for protocols, with the three core protocols being NETCONF, RESTCONF, and gRPC</li>
</ul>
<p>Now that we have an idea of what a data model is and the role model-driven programmability plays in API architecture, then this would be a good time to take the 50,000-foot overview of model-driven programmability's role in network automation. Consider the following figure:
<img decoding="async" loading="lazy" src="https://docs.tanthanh.dev/vi/assets/images/data_models-3f6103aed9e98bab93e4bbdabd1a979b.jpg" width="795" height="365" class="img_ev3q">
Applications can now use programming libraries or development kits that leverage data models to simplify access to the API. Behind the scenes, different protocols using various encodings and transports may be used to exchange data but the application does not need to concern itself with that. It only needs to operate on the data models. Likewise, the API server uses the same model, regardless of the protocol, allowing the server to support as many protocols as required.</p>
<p>Imagine that an application has requested to retrieve an IP address on an interface of a network device. The data request is structured according to the application's YANG data model. The application then sends a request to the API server on the network device. The network device can identify what data the request asks and constructs a response for the application. The response is formatted in an expected structure or model that the application is expecting based on YANG. For example, if the request were for an IP address on an interface, it would use the proper data model for interface IP addresses. The network device sends the response back and is received by the application. The data structure is in a format that the application expects since both sides are using the YANG data model. The figure demonstrates the role of data models in network automation in action.
<img decoding="async" loading="lazy" src="https://docs.tanthanh.dev/vi/assets/images/MDP_in_action-9722c3bdef384ca48091242437a0716d.jpeg" width="1026" height="464" class="img_ev3q"></p>
<p>The two main data encoding formats commonly used are XML and JSON. Each provides a structured way of data formatting to send data between two computer systems. Since data conforms to the model, it is easier to navigate and extract relevant information programmatically. This is in stark contrast to using Secure Shell (SSH) issuing CLI commands in which data is sent as raw strings (text).</p>
<p>Sometimes the concept of data models gets confused with data encoding formats like XML and JSON. The data encoding formats involve the serialization format of how the data is transmitted. More simply stated, XML and JSON are not about the framework of how wer model is presented but the way the data is formatted for transport.</p>
<p>XML and JSON are used for data transmission because they have these features:</p>
<ul>
<li class="">Human readable because they are self-describing</li>
<li class="">Hierarchical, because they store values within values</li>
<li class="">Parsable and used by many programming languages</li>
</ul>
<p>As we finish up, it is worth mentioning YANG, which is a data modeling language we will likely encounter on wer network automation journey.</p>
<p><img decoding="async" loading="lazy" src="https://docs.tanthanh.dev/vi/assets/images/YANG_sample-5b48a36ad107c6f941271bd0bb6259d5.jpg" width="339" height="201" class="img_ev3q"></p>
<p>There are whole courses and even books dedicated to YANG, but for now, it is important to understand that YANG is a data modeling language used by protocols like NETCONF, RESTCONF, and gRPC. The YANG data modeling language was published in October 2010 as RFC 6020 to serve as a data modeling language for the protocol NETCONF. So to finally put it all together, the image below illustrates the YANG model-driven programmability stack.</p>
<p><img decoding="async" loading="lazy" src="https://docs.tanthanh.dev/vi/assets/images/DM_language_YANG-5a166a95ba42f356caf5edd0e7860206.jpg" width="794" height="366" class="img_ev3q">
As we can see, data models are not really new but are getting more attention as a building block of model-driven APIs.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="references">References<a href="https://docs.tanthanh.dev/vi/blog/network-automation/model-driven-programmability#references" class="hash-link" aria-label="Đường dẫn trực tiếp đến References" title="Đường dẫn trực tiếp đến References" translate="no">​</a></h2>
<ul>
<li class="">The YANG Data Modeling Language: <a href="https://tools.ietf.org/html/rfc7950" target="_blank" rel="noopener noreferrer" class="">https://tools.ietf.org/html/rfc7950</a></li>
<li class="">NETCONF and RESTCONF: <a href="https://www.ietf.org/rfc/rfc6241.txt" target="_blank" rel="noopener noreferrer" class="">https://www.ietf.org/rfc/rfc6241.txt</a></li>
<li class="">gRPC: <a href="https://grpc.io/" target="_blank" rel="noopener noreferrer" class="">https://grpc.io/</a></li>
</ul>]]></content:encoded>
            <category>network</category>
            <category>automation</category>
            <category>model-driven</category>
        </item>
        <item>
            <title><![CDATA[Should be elegance in Python or not?]]></title>
            <link>https://docs.tanthanh.dev/vi/blog/python/elegance-python</link>
            <guid>https://docs.tanthanh.dev/vi/blog/python/elegance-python</guid>
            <pubDate>Sat, 22 Jul 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[Practical tips for writing elegant, readable, and maintainable Python code with real-world examples and best practices.]]></description>
            <content:encoded><![CDATA[<p>While I am not an expert in Python, I always strive to enhance my code during the development process and I believe that everyone should aim to do so as well. As a result of my efforts, I have noticed significant improvements, particularly in terms of code readability and maintainability. Thus, I would like to share some insights on why elegance matters in Python.</p>
<div class="theme-admonition theme-admonition-caution admonition_xJq3 alert alert--warning"><div class="admonitionHeading_Gvgb"><span class="admonitionIcon_Rf37"><svg viewBox="0 0 16 16"><path fill-rule="evenodd" d="M8.893 1.5c-.183-.31-.52-.5-.887-.5s-.703.19-.886.5L.138 13.499a.98.98 0 0 0 0 1.001c.193.31.53.501.886.501h13.964c.367 0 .704-.19.877-.5a1.03 1.03 0 0 0 .01-1.002L8.893 1.5zm.133 11.497H6.987v-2.003h2.039v2.003zm0-3.004H6.987V5.987h2.039v4.006z"></path></svg></span>cẩn thận</div><div class="admonitionContent_BuS1"><p>These are all subjective things. That means that there is no single right way to write Python code. What works for one person may not work for another.
If you disagree with anything I say, I encourage you to leave a comment or write me an email. Diversity of opinion is enriching, and I am always happy to learn new things.</p></div></div>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="introduction">Introduction<a href="https://docs.tanthanh.dev/vi/blog/python/elegance-python#introduction" class="hash-link" aria-label="Đường dẫn trực tiếp đến Introduction" title="Đường dẫn trực tiếp đến Introduction" translate="no">​</a></h2>
<p>In software development, there is a common debate about whether elegance matters. Some people believe that the most important thing is to get the job done, regardless of how the code looks. Others believe that code should be elegant, readable, and easy to maintain.</p>
<p>In Python, elegance is often considered to be more important than in other programming languages. This is because Python is a very expressive language, and it is possible to write code that is both concise and readable.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="the-reasons-why-elegance-matters-in-python">The reasons why elegance matters in Python.<a href="https://docs.tanthanh.dev/vi/blog/python/elegance-python#the-reasons-why-elegance-matters-in-python" class="hash-link" aria-label="Đường dẫn trực tiếp đến The reasons why elegance matters in Python." title="Đường dẫn trực tiếp đến The reasons why elegance matters in Python." translate="no">​</a></h2>
<p>First, it makes code easier to read and understand. This is important for anyone who needs to work on the code in the future, whether it is the original author or someone else.</p>
<p>Second, elegant code is more likely to be maintainable. This is because it is easier to modify and update. If a piece of code is not elegant, it can be difficult to figure out how it works, and this can make it difficult to make changes.</p>
<p>Third, elegant code is more likely to be reusable. This is because it is easier to understand and adapt to other projects. If a piece of code is not elegant, it can be difficult to use in other contexts.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="dont-call-code-unreadable-just-because-you-dont-understand-it">Don't call code unreadable just because you don't understand it<a href="https://docs.tanthanh.dev/vi/blog/python/elegance-python#dont-call-code-unreadable-just-because-you-dont-understand-it" class="hash-link" aria-label="Đường dẫn trực tiếp đến Don't call code unreadable just because you don't understand it" title="Đường dẫn trực tiếp đến Don't call code unreadable just because you don't understand it" translate="no">​</a></h2>
<p>If you see code that you don't understand, don't be quick to call it unreadable. It's possible that the code is perfectly readable, but you just don't know how to read it.</p>
<p>For example, if you don't know the Assembly Language you might look at an expression and think it's unreadable. But to an AL programmer, the expression is perfectly readable.</p>
<details class="details_lb9f alert alert--info details_b_Ee" data-collapsed="true"><summary>Python vs Assembly Language: </summary><div><div class="collapsibleContent_i85q"><div class="theme-tabs-container tabs-container tabList__CuJ"><ul role="tablist" aria-orientation="horizontal" class="tabs"><li role="tab" tabindex="0" aria-selected="true" class="tabs__item tabItem_LNqP tabs__item--active">Python</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">Assembly Language</li></ul><div class="margin-top--md"><div role="tabpanel" class="tabItem_Ymn6"><div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">add</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">a</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> b</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> a </span><span class="token operator" style="color:#393A34">+</span><span class="token plain"> b</span><br></div></code></pre></div></div></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><div class="language-asm codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-asm codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token plain">add:</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">   mov rax, rdi</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">   add rax, rsi</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">   ret</span><br></div></code></pre></div></div></div></div></div></div></div></details>
<p>In general, something is unreadable when you know what all the constituent pieces mean, and yet the pieces are put together in a way that doesn't convey the global meaning well. This could be due to the usage of the wrong constituent pieces, because pieces are missing, because there are superfluous pieces, etc.</p>
<p>So, if you see code that you don't understand, don't call it unreadable. Take the time to learn what the different pieces mean, and then you can judge whether the code is well-written or not.</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="when-looking-back">When looking back..<a href="https://docs.tanthanh.dev/vi/blog/python/elegance-python#when-looking-back" class="hash-link" aria-label="Đường dẫn trực tiếp đến When looking back.." title="Đường dẫn trực tiếp đến When looking back.." translate="no">​</a></h2>
<p>If you are constantly learning, you will eventually look back at your old code and think "I know a better way to do that." If you write simple and elegant code, you will be able to understand your old code quickly and easily, so you can modify it to include the new, improved solution. This will make your code even clearer and more elegant, and the cycle can continue indefinitely.</p>
<p>Idiomatic code is code whose semantics are easy to understand. If you write idiomatic code, you are opening up the doors for future rewrites of your code. This is a good thing, because code that can be changed is code that can be improved over time.</p>
<p>So, the next time you sit down to write some code, ask yourself: do I want to write code that is easy to understand and modify, or do I want to write code that everyone (including my future self) is scared of going near to?</p>
<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="a-few-tips-for-writing-elegant-python-code">A few tips for writing elegant Python code<a href="https://docs.tanthanh.dev/vi/blog/python/elegance-python#a-few-tips-for-writing-elegant-python-code" class="hash-link" aria-label="Đường dẫn trực tiếp đến A few tips for writing elegant Python code" title="Đường dẫn trực tiếp đến A few tips for writing elegant Python code" translate="no">​</a></h2>
<p>Of course, there are times when elegance is not the most important consideration. For example, if you are writing code that will only be used once, then it may not be worth the time to make it elegant. However, in general, elegance is a good thing to strive for in Python.</p>
<p>Here are a few tips for writing elegant Python code:</p>
<ul>
<li class="">Use the right tool for the job. Don't use a complex feature if a simpler one will do the job just as well.</li>
<li class="">Use idiomatic code. This means using the features of the language in the way that they were intended to be used.</li>
<li class="">Keep your code concise. This doesn't mean that you should always write the shortest possible code, but it does mean that you should avoid writing code that is unnecessarily long or complex.</li>
<li class="">Use comments. Comments can help to explain what your code is doing, which can make it easier to read and understand. (optional)</li>
<li class="">Test your code. This will help to ensure that it works as expected, and it will also make it easier to debug if something goes wrong.</li>
</ul>]]></content:encoded>
            <category>python</category>
            <category>elegance</category>
            <category>tips</category>
        </item>
        <item>
            <title><![CDATA[Usage of underscore in Python]]></title>
            <link>https://docs.tanthanh.dev/vi/blog/python/underscore-usage</link>
            <guid>https://docs.tanthanh.dev/vi/blog/python/underscore-usage</guid>
            <pubDate>Sun, 09 Jul 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[A detailed guide to the many uses of underscores in Python, from throwaway variables to name mangling and internationalization.]]></description>
            <content:encoded><![CDATA[<ol>
<li class="">Last used value in python console</li>
</ol>
<div class="language-bash codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-bash codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token operator" style="color:#393A34">&gt;&gt;</span><span class="token operator" style="color:#393A34">&gt;</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">10</span><span class="token plain"> + </span><span class="token number" style="color:#36acaa">10</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token number" style="color:#36acaa">20</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">&gt;&gt;</span><span class="token plain"> _ * </span><span class="token number" style="color:#36acaa">2</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token number" style="color:#36acaa">40</span><br></div></code></pre></div></div>
<ol start="2">
<li class="">Make number more readable</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token plain">number</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> </span><span class="token builtin">int</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1_000_000</span><br></div></code></pre></div></div>
<ol start="3">
<li class="">Unimportant values</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">for</span><span class="token plain"> _ </span><span class="token keyword" style="color:#00009f">in</span><span class="token plain"> </span><span class="token builtin">range</span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">3</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">'hello'</span><span class="token punctuation" style="color:#393A34">)</span><br></div></code></pre></div></div>
<ol start="4">
<li class="">Unimportant exception</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">try</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">  result </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">1</span><span class="token operator" style="color:#393A34">/</span><span class="token number" style="color:#36acaa">0</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">except</span><span class="token plain"> ZeroDivisionError </span><span class="token keyword" style="color:#00009f">as</span><span class="token plain"> </span><span class="token keyword" style="color:#00009f">_</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">   </span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token string" style="color:#e3116c">'Handled.'</span><span class="token punctuation" style="color:#393A34">)</span><br></div></code></pre></div></div>
<ol start="5">
<li class="">Unpacking</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token plain">sample_tuple </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">,</span><span class="token number" style="color:#36acaa">3</span><span class="token punctuation" style="color:#393A34">,</span><span class="token number" style="color:#36acaa">4</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">a</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> _</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> b</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> _ </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> sample_tuple</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">a</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain">b</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"> </span><span class="token comment" style="color:#999988;font-style:italic"># 1, 3</span><br></div></code></pre></div></div>
<ol start="6">
<li class="">Super Unpacking</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token plain">sample_tuple </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token punctuation" style="color:#393A34">(</span><span class="token number" style="color:#36acaa">1</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">2</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">3</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">4</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">5</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">a</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">*</span><span class="token plain">_</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> b </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> sample_tuple</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">a</span><span class="token punctuation" style="color:#393A34">,</span><span class="token plain"> b</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain">  </span><span class="token comment" style="color:#999988;font-style:italic">#1, 5</span><br></div></code></pre></div></div>
<ol start="7">
<li class="">protected</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">from</span><span class="token plain"> uuid </span><span class="token keyword" style="color:#00009f">import</span><span class="token plain"> uuid4</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">class</span><span class="token plain"> </span><span class="token class-name">User</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">__init__</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">self</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        self</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">_id </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> uuid4</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">_get_id</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">self</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">        </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> self</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">_id</span><br></div><div class="token-line" style="color:#393A34"><span class="token plain" style="display:inline-block"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">user </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> User</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token comment" style="color:#999988;font-style:italic"># typing user. will not show _get_id from IDE</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">user</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">_get_id</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><br></div></code></pre></div></div>
<ol start="8">
<li class="">Private</li>
</ol>
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">__init__</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">self</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    self</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">__id </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> uuid4</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">__get_id</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">self</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">    </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> self</span><span class="token punctuation" style="color:#393A34">.</span><span class="token plain">__id</span><br></div></code></pre></div></div>
<ol start="9">
<li class="">Reserved names</li>
</ol>
<div class="language-py codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-py codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token plain">if_ </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token number" style="color:#36acaa">10</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">class_ </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"class"</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">str_ </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> </span><span class="token string" style="color:#e3116c">"str"</span><br></div></code></pre></div></div>
<ol start="10">
<li class="">dundor method</li>
</ol>
<div class="language-py codeBlockContainer_Ckt0 theme-code-block" style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><div class="codeBlockContent_QJqH"><pre tabindex="0" class="prism-code language-py codeBlock_bY9V thin-scrollbar" style="color:#393A34;background-color:#f6f8fa"><code class="codeBlockLines_e6Vv"><div class="token-line" style="color:#393A34"><span class="token keyword" style="color:#00009f">class</span><span class="token plain"> </span><span class="token class-name">Fruit</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">__init__</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">self</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">      self</span><span class="token punctuation" style="color:#393A34">.</span><span class="token builtin">id</span><span class="token plain"> </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> uuid4</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">  </span><span class="token keyword" style="color:#00009f">def</span><span class="token plain"> </span><span class="token function" style="color:#d73a49">__str__</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">self</span><span class="token punctuation" style="color:#393A34">)</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">      </span><span class="token keyword" style="color:#00009f">return</span><span class="token plain"> </span><span class="token string-interpolation string" style="color:#e3116c">f"Fruit: </span><span class="token string-interpolation interpolation punctuation" style="color:#393A34">{</span><span class="token string-interpolation interpolation">self</span><span class="token string-interpolation interpolation punctuation" style="color:#393A34">.</span><span class="token string-interpolation interpolation builtin">id</span><span class="token string-interpolation interpolation punctuation" style="color:#393A34">}</span><span class="token string-interpolation string" style="color:#e3116c">"</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain">fruit </span><span class="token operator" style="color:#393A34">=</span><span class="token plain"> Fruit</span><span class="token punctuation" style="color:#393A34">(</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token keyword" style="color:#00009f">print</span><span class="token punctuation" style="color:#393A34">(</span><span class="token plain">fruit</span><span class="token punctuation" style="color:#393A34">)</span><span class="token plain"></span><br></div><div class="token-line" style="color:#393A34"><span class="token plain"></span><span class="token operator" style="color:#393A34">&gt;&gt;</span><span class="token operator" style="color:#393A34">&gt;</span><span class="token plain"> Fruit</span><span class="token punctuation" style="color:#393A34">:</span><span class="token plain"> 6075f5a9</span><span class="token operator" style="color:#393A34">-</span><span class="token plain">24bf</span><span class="token operator" style="color:#393A34">-</span><span class="token plain">4df3</span><span class="token operator" style="color:#393A34">-</span><span class="token plain">b1ba</span><span class="token operator" style="color:#393A34">-</span><span class="token plain">3fea2100dd4d</span><br></div></code></pre></div></div>]]></content:encoded>
            <category>python</category>
            <category>underscore</category>
            <category>tips</category>
        </item>
        <item>
            <title><![CDATA[Welcome]]></title>
            <link>https://docs.tanthanh.dev/vi/blog/welcome</link>
            <guid>https://docs.tanthanh.dev/vi/blog/welcome</guid>
            <pubDate>Sun, 09 Jul 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[Welcome to my knowledge sharing platform - a space for technical documentation, tutorials, and continuous learning.]]></description>
            <content:encoded><![CDATA[<h2 class="anchor anchorTargetStickyNavbar_Vzrq" id="welcome-to-my-website">Welcome to My Website!<a href="https://docs.tanthanh.dev/vi/blog/welcome#welcome-to-my-website" class="hash-link" aria-label="Đường dẫn trực tiếp đến Welcome to My Website!" title="Đường dẫn trực tiếp đến Welcome to My Website!" translate="no">​</a></h2>
<div style="text-align:justify"><p>Welcome to the site where I share my knowledge and experience in API, network, web, and mobile automation, as well as other useful tips and tricks in Python and other programming languages that I am proficient in! This documentation is intended to provide notes, tips, and best practices for Python automation testing in web and networking contexts, whether you're an experienced tester or just starting out with Python.</p><p>I will be updating this documentation regularly with the latest information and insights, so be sure to check back often for new updates. If you have any questions, comments, or suggestions for topics you would like to see covered in this documentation, please don't hesitate to contact me.</p><p>Thank you for visiting this documentation, and I hope you find it helpful and informative on your Python automation testing journey!</p><p>Best regards,</p><p><a href="https://www.linkedin.com/in/ngtanthanh/" target="_blank" rel="noopener noreferrer" class="">Thanh Nguyen</a></p></div>]]></content:encoded>
            <category>welcome</category>
            <category>intro</category>
        </item>
    </channel>
</rss>