<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: yosi</title>
    <description>The latest articles on DEV Community by yosi (@yosi).</description>
    <link>https://dev.to/yosi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F146376%2Fb40a1714-8ecb-4fe3-8792-aca4f31b438a.png</url>
      <title>DEV Community: yosi</title>
      <link>https://dev.to/yosi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yosi"/>
    <language>en</language>
    <item>
      <title>Enhancing Your Crypto Trading Experience with a Crypto Screener</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Sat, 05 Oct 2024 16:21:41 +0000</pubDate>
      <link>https://dev.to/yosi/enhancing-your-crypto-trading-experience-with-a-crypto-screener-401n</link>
      <guid>https://dev.to/yosi/enhancing-your-crypto-trading-experience-with-a-crypto-screener-401n</guid>
      <description>&lt;p&gt;The cryptocurrency market is a dynamic and fast-paced world that offers tremendous opportunities for traders and investors alike. With thousands of digital currencies available and 24/7 trading, it's no surprise that many traders find it difficult to keep up with market trends, technical signals, and sentiment analysis. This is where a &lt;strong&gt;crypto screener&lt;/strong&gt; can become a powerful tool in a trader's arsenal.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Crypto Screener?
&lt;/h2&gt;

&lt;p&gt;A crypto screener is a digital tool designed to help traders filter through the vast number of cryptocurrencies based on specific criteria. Much like stock screeners in traditional markets, a crypto screener allows users to sift through coins based on factors like price movements, volume, market capitalization, technical indicators, and even sentiment analysis. It simplifies the process of finding potential trading opportunities, saving both time and effort.&lt;/p&gt;

&lt;p&gt;By using a crypto screener, traders can identify opportunities that align with their trading strategies. Whether you're a day trader looking for short-term gains or a long-term investor searching for undervalued assets, a crypto screener can be tailored to your specific needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Features of a Crypto Screener
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-Time Data&lt;/strong&gt;: The most important feature of any crypto screener is access to real-time market data. Cryptocurrencies trade 24/7, and being able to quickly identify price changes or volume spikes is critical for seizing trading opportunities. A high-quality screener ensures that traders are always in sync with the latest market conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Technical Indicators&lt;/strong&gt;: Many traders rely on technical analysis to guide their decisions. Crypto screeners often come equipped with technical indicators like Relative Strength Index (RSI), Moving Averages, Bollinger Bands, and more. These indicators provide insights into the momentum and potential reversal points of a cryptocurrency, making it easier to pinpoint buying and selling opportunities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sentiment Analysis&lt;/strong&gt;: The crypto market is highly influenced by news, social media trends, and overall market sentiment. Some advanced screeners also integrate sentiment analysis to gauge the emotional tone of discussions surrounding a specific cryptocurrency. This can help traders get ahead of market-moving events or identify assets that are being talked about positively (or negatively).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Filters&lt;/strong&gt;: Crypto screeners allow traders to set custom filters based on their personal trading criteria. Want to find coins with a 5% price increase in the last 24 hours and a market cap over $1 billion? A screener can help you do just that. Customization makes it possible to create highly specific strategies based on your trading style.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Alerts and Notifications&lt;/strong&gt;: A well-designed crypto screener doesn't just help you find opportunities but also notifies you of market conditions that match your criteria. Alerts ensure that traders never miss out on a trade when they aren’t actively monitoring the market.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How a Crypto Screener Improves Your Trading Experience
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Efficiency&lt;/strong&gt;: Without a screener, traders would have to manually browse through numerous coins and try to spot patterns, which can be time-consuming and inefficient. A crypto screener automates this process, allowing traders to scan hundreds of cryptocurrencies in seconds.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Informed Decision-Making&lt;/strong&gt;: Crypto screeners provide traders with critical insights based on data. Instead of relying on guesswork or emotional reactions, traders can make informed decisions using technical indicators, sentiment analysis, and historical price patterns.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Risk Management&lt;/strong&gt;: Many traders use screeners to implement strict risk management strategies. By identifying assets with low volatility or those that meet specific risk thresholds, traders can avoid overexposing themselves to highly volatile coins or uncertain market conditions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Versatility&lt;/strong&gt;: Whether you are focused on technical analysis, fundamental data, or sentiment trends, a crypto screener caters to different strategies. You can use it to focus on short-term day trades, or for finding long-term investment opportunities based on fundamental growth indicators.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Staying Ahead of the Market&lt;/strong&gt;: The crypto market moves fast, and it’s easy to miss out on trading opportunities. A crypto screener ensures that you stay ahead of the game by filtering out noise and providing actionable insights based on the criteria that matter most to you.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Why You Should Consider Using a Crypto Screener
&lt;/h2&gt;

&lt;p&gt;Crypto screeners aren't just for expert traders; they are valuable tools for anyone looking to improve their trading experience. Whether you're a beginner trying to learn the ropes or an experienced trader seeking an edge, a well-configured screener can offer a significant advantage.&lt;/p&gt;

&lt;p&gt;For instance, if you’re looking to implement a strategy based on sentiment and technical analysis, a tool like &lt;strong&gt;&lt;a href="https://cointool.com" rel="noopener noreferrer"&gt;CoinTool&lt;/a&gt;&lt;/strong&gt;, a screener designed for such purposes, could be exactly what you need. It simplifies the process of identifying market trends and technical setups while providing real-time sentiment insights that can help predict short-term market movements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;The cryptocurrency market is a challenging and often unpredictable space. By leveraging the power of a crypto screener, traders can significantly enhance their trading experience. Whether you’re focused on maximizing profits, minimizing risk, or simply staying ahead of market trends, a screener can help you navigate the complexities of the crypto market with confidence.&lt;/p&gt;

&lt;p&gt;In a market where timing is everything, using a crypto screener could be the key to unlocking better opportunities and improving your overall trading strategy. So if you’re serious about crypto trading, consider adding a crypto screener to your toolkit—your portfolio will thank you.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Getting Started with Hardhat for Smart Contracts</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Sun, 04 Jun 2023 08:54:05 +0000</pubDate>
      <link>https://dev.to/yosi/getting-started-with-hardhat-for-smart-contracts-fc</link>
      <guid>https://dev.to/yosi/getting-started-with-hardhat-for-smart-contracts-fc</guid>
      <description>&lt;p&gt;In the world of Ethereum development, one tool stands out for its robustness and versatility: &lt;a href="https://hardhat.org/"&gt;Hardhat&lt;/a&gt;. This tool is designed to help developers manage, test, and deploy smart contracts on Ethereum with ease. In this post, we'll dive into what Hardhat is, how it works, and how it uses RPC. Moreover, we'll walk you through the steps of compiling and interacting with smart contracts using Hardhat (on a test environment).&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Hardhat?
&lt;/h2&gt;

&lt;p&gt;Hardhat is a development environment and task runner for Ethereum that helps developers build and interact with smart contracts. It is designed to provide developers with a seamless experience in writing, testing, and deploying smart contracts. It comes with built-in TypeScript support, debugging, and networking capabilities, making it a one-stop-shop for Ethereum development.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it Works?
&lt;/h2&gt;

&lt;p&gt;Hardhat works by setting up a local Ethereum network on your machine for development purposes. This local network, called Hardhat Network, allows you to execute and test your smart contracts in a controlled environment. It provides detailed error messages and console.log functionality, which makes debugging a breeze.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hardhat and RPC
&lt;/h2&gt;

&lt;p&gt;The Hardhat Network communicates with your Ethereum node via an API called JSON-RPC (Remote Procedure Call). RPC allows a client to interact with a remote server. In the case of Hardhat, it connects to the Ethereum node (either a local one or a remote one) and sends requests to interact with the blockchain, like deploying a smart contract or querying a transaction. Hardhat uses the Ethereum JSON-RPC API, which is a set of methods used to interact with the Ethereum network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compiling and Interacting with Smart Contracts
&lt;/h2&gt;

&lt;p&gt;Lets walk through an example of compiling and interacting with a smart contract using Hardhat.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Install Hardhat
&lt;/h3&gt;

&lt;p&gt;First, you need to install Hardhat. Make sure you have Node.js installed, then run the following command in your terminal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; hardhat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 2: Create a New Hardhat Project
&lt;/h3&gt;

&lt;p&gt;Next, create a new Hardhat project by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx hardhat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose "Create an empty hardhat.config.js" when prompted. This will create a new directory with the necessary configuration file (hardhat.config.js) in the root folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 3: Write The Smart Contract
&lt;/h3&gt;

&lt;p&gt;Create a new file in the contracts directory (/contracts), say HelloWorld.sol, and add the following Solidity code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.7.3;

contract HelloWorld {
    function sayHello() public pure returns (string memory) {
        return "Hello, Hardhat!";
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Compile The Smart Contract
&lt;/h3&gt;

&lt;p&gt;Compile the smart contract by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx hardhat compile
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 5: Write a Test
&lt;/h3&gt;

&lt;p&gt;Create a new file in the test directory (/test), say HelloWorld.test.js, and add the following JS code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;chai&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HelloWorld contract&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Should return the right greeting&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContractFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HelloWorld&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deployed&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, Hardhat!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Let's break it down:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;expect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;chai&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line imports the expect function from the chai library, which is a popular JavaScript testing library. expect is used to make assertions about your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContractFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;HelloWorld&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line creates a contract factory for the HelloWorld contract. A contract factory is an object that can be used to deploy new instances of a contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line deploys an instance of the HelloWorld contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deployed&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line waits for the contract to be deployed. Contract deployment is an asynchronous operation that involves a transaction being mined on the Ethereum network.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;helloWorld&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sayHello&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, Hardhat!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line calls the sayHello function of the HelloWorld contract and checks that it returns the string "Hello, Hardhat!". &lt;/p&gt;

&lt;h3&gt;
  
  
  Step 6: Run The Test
&lt;/h3&gt;

&lt;p&gt;Run the test by executing the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx hardhat &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything is set up correctly, you should see a message saying your test passed.&lt;/p&gt;

&lt;p&gt;That's it! You have just written, compiled, deployed (to a test network) and tested a smart contract with Hardhat.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software. It helps developers manage and automate the recurring tasks involved in building smart contracts and performing complex deployments. 🚀&lt;/p&gt;

</description>
      <category>node</category>
      <category>ethereum</category>
      <category>solidity</category>
      <category>hardhat</category>
    </item>
    <item>
      <title>A Quick Guide to Regular Expressions in Python</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Sun, 28 May 2023 01:30:42 +0000</pubDate>
      <link>https://dev.to/yosi/mastering-text-patterns-with-regular-expressions-in-python-22go</link>
      <guid>https://dev.to/yosi/mastering-text-patterns-with-regular-expressions-in-python-22go</guid>
      <description>&lt;p&gt;Text processing is an integral part of many programming tasks, and one powerful tool that can greatly simplify these tasks is regular expressions. Regular expressions, often abbreviated as regex, provide a concise and flexible way to match, search, and manipulate text patterns in Python. In this post, we will explore the re module in Python and demonstrate how regular expressions can be used to solve text processing challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Regular Expressions?
&lt;/h2&gt;

&lt;p&gt;A regular expression is a sequence of characters that forms a search pattern. It enables you to specify a set of rules that define the desired pattern you want to match within a given text. Regular expressions are not exclusive to Python; they are a standardized concept found in many programming languages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the re Module
&lt;/h2&gt;

&lt;p&gt;Python provides the re module, which is a built-in library that offers functions and methods for working with regular expressions. To start using regular expressions in your Python code, you need to import the re module.&lt;/p&gt;

&lt;h2&gt;
  
  
  Matching Patterns
&lt;/h2&gt;

&lt;p&gt;The most basic operation with regular expressions is pattern matching. The re module provides the match() function, which checks if a pattern matches the beginning of a string. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pattern matched!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pattern not found.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we defined a pattern "Hello" and a string "Hello, World!". The match() function returns a match object if the pattern is found at the beginning of the string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Searching Patterns
&lt;/h2&gt;

&lt;p&gt;Regular expressions excel at searching and replacing patterns within text. The search() function in the re module allows you to find the first occurrence of a pattern within a string. Once a match is found, you can use the group() method to extract the matched portion. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;World&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pattern found:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;group&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Pattern not found.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the pattern "World" is found in the string "Hello, World!" using the search() function. The group() method retrieves the matched portion, which is then printed as output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modifiers and Special Sequences
&lt;/h2&gt;

&lt;p&gt;Regular expressions support modifiers and special sequences to enhance pattern matching. &lt;br&gt;
Some commonly used modifiers include:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Modifier&lt;/th&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;re.I&lt;/td&gt;
&lt;td&gt;Performs case-insensitive matching.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;re.M&lt;/td&gt;
&lt;td&gt;Enables multi-line matching.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;re.S&lt;/td&gt;
&lt;td&gt;Allows the dot character to match newline characters.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Special sequences include:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Sequence&lt;/th&gt;
&lt;th&gt;Pattern&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;\d&lt;/td&gt;
&lt;td&gt;Matches any digit character.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;\w&lt;/td&gt;
&lt;td&gt;Matches any alphanumeric character and underscores.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;\s&lt;/td&gt;
&lt;td&gt;Matches any whitespace character.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;.&lt;/td&gt;
&lt;td&gt;Matches any character except a newline.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td&gt;Matches the expression to its left 0 or more times.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;

&lt;span class="c1"&gt;# Example text
&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello World&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;Hello Python&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;HELLO WORLD&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="c1"&gt;# Case-insensitive matching with re.I (ignorecase) modifier
&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;I&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# ['Hello', 'Hello', 'HELLO']
&lt;/span&gt;
&lt;span class="c1"&gt;# Multi-line matching with re.M (multiline) modifier
&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;^hello&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;M&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# ['Hello', 'Hello']
&lt;/span&gt;
&lt;span class="c1"&gt;# Dot matches any character, including a newline
&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Hello.*World&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;findall&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pattern&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;S&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# ['Hello World', 'Hello Python\nHELLO WORLD']
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Regular expressions provide a powerful and efficient way to handle complex text patterns. With the ability to match, search, and replace text based on specific rules, regular expressions are indispensable for tasks like data validation, web scraping, and text manipulation. By mastering regular expressions, you can unlock a whole new level of flexibility and control in your text processing endeavors. 🚀&lt;/p&gt;

</description>
      <category>python</category>
      <category>re</category>
      <category>regex</category>
    </item>
    <item>
      <title>Building a Python Web App with Flask and Nginx</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Sat, 27 May 2023 19:33:03 +0000</pubDate>
      <link>https://dev.to/yosi/building-a-python-web-app-with-flask-and-nginx-5ah3</link>
      <guid>https://dev.to/yosi/building-a-python-web-app-with-flask-and-nginx-5ah3</guid>
      <description>&lt;p&gt;In Python web development, two essential components come into play: web frameworks and web servers. While they work together to handle incoming requests and generate responses, they have distinct roles. In this article, we'll explore the difference between them and understand the role of WSGI (Web Server Gateway Interface).&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Frameworks
&lt;/h2&gt;

&lt;p&gt;A web framework is a software library or toolkit that simplifies web application development. It provides a set of pre-defined tools, utilities, and abstractions to streamline common web development tasks. These frameworks handle crucial aspects such as URL routing, request handling, database integration, templating, and more. Python boasts several popular web frameworks, including Django, Flask, and Pyramid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Web Servers
&lt;/h2&gt;

&lt;p&gt;On the other hand, a web server is responsible for receiving incoming HTTP requests from clients (e.g., web browsers) and sending back HTTP responses. It serves as the intermediary between clients and web applications. Web servers listen on specific network ports, handle low-level communication, and manage the execution of web applications. Commonly used web servers with Python include Apache HTTP Server, Nginx, and Gunicorn.&lt;/p&gt;

&lt;h2&gt;
  
  
  WSGI
&lt;/h2&gt;

&lt;p&gt;The Web Server Gateway Interface (WSGI) acts as a standard interface between web servers and web applications or frameworks in Python. It establishes a bridge that allows communication between these components. WSGI defines a set of methods that web servers call on web applications or frameworks to handle requests and generate responses.&lt;/p&gt;

&lt;p&gt;This separation of concerns facilitated by WSGI allows different web servers and web frameworks to seamlessly work together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Flask and Ngnix
&lt;/h2&gt;

&lt;p&gt;Lets explore the process of building a Python web application using Flask, a lightweight and flexible web framework, along with Nginx, a high-performance web server. By combining Flask's simplicity with Nginx's scalability, we can create a robust and efficient web application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Setting up Flask
&lt;/h3&gt;

&lt;p&gt;Begin by installing Flask using pip, Python's package installer. Open a terminal or command prompt and run the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install flask
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, create a Flask application. Create a new file (app.py), import Flask and define a Flask application instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;flask&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Flask&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Flask&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;__name__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Define the routes and start the development server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nd"&gt;@app.route&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;hello&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Hello, World!&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;debug&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, In the terminal or command prompt, execute the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test the application: Open a web browser and visit &lt;a href="http://localhost:5000/"&gt;http://localhost:5000/&lt;/a&gt;. You should see the "Hello, World!" message displayed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Configuring Nginx
&lt;/h3&gt;

&lt;p&gt;Install Nginx on your server following the instructions relevant to your operating system.&lt;/p&gt;

&lt;p&gt;Configure Nginx as a reverse proxy - Open the Nginx configuration file, typically located at /etc/nginx/nginx.conf, and add the following configuration block within the http context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server {
    listen 80;
    server_name your_domain.com;

    location / {
        proxy_pass http://localhost:5000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace your_domain.com with your domain name or IP address.&lt;/p&gt;

&lt;p&gt;Save the configuration file and exit the editor. Apply the configuration changes by restarting Nginx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo service nginx restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With Nginx serving as a reverse proxy, you can access your Flask application by visiting your domain name or IP address in a web browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;WSGI allows different web servers and web frameworks to seamlessly work together. By leveraging the simplicity of Flask and the performance of Nginx, we can build and deploy robust Python web applications. 🚀&lt;/p&gt;

</description>
      <category>python</category>
      <category>wsgi</category>
      <category>flask</category>
      <category>ngnix</category>
    </item>
    <item>
      <title>Understanding the Difference between nonlocal and global in Python</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Sat, 27 May 2023 01:34:07 +0000</pubDate>
      <link>https://dev.to/yosi/understanding-the-difference-between-nonlocal-and-global-in-python-40eg</link>
      <guid>https://dev.to/yosi/understanding-the-difference-between-nonlocal-and-global-in-python-40eg</guid>
      <description>&lt;p&gt;Python, being a versatile and powerful programming language, provides two keywords, nonlocal and global, to access variables defined in outer scopes. While these keywords serve a similar purpose, they have distinct behaviors and use cases. In this blog post, we'll explore the difference between nonlocal and global in Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  The nonlocal Keyword
&lt;/h2&gt;

&lt;p&gt;The nonlocal keyword is used to indicate that a variable is defined in an outer function scope, often referred to as a non-local scope. It is particularly useful when working with nested functions. By using the nonlocal keyword, you can access and modify variables from the outer scope within an inner function.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example to illustrate its usage:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;outer_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;inner_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
        &lt;span class="k"&gt;nonlocal&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
        &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: 20
&lt;/span&gt;
    &lt;span class="nf"&gt;inner_function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: 20
&lt;/span&gt;
&lt;span class="nf"&gt;outer_function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, we have an outer function called outer_function(), which defines a variable x with an initial value of 10. Inside outer_function(), we have an inner function called inner_function(), where we declare x as a nonlocal variable using the nonlocal keyword. We then assign a new value of 20 to x and print it, resulting in the output of 20. The change in the value of x persists even after the inner_function() has finished executing, as seen by the subsequent print statement in outer_function().&lt;/p&gt;

&lt;p&gt;The nonlocal keyword allows us to modify variables in the outer scope from within nested functions, providing a way to communicate and share data between the inner and outer functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The global Keyword
&lt;/h2&gt;

&lt;p&gt;On the other hand, the global keyword is used to indicate that a variable is defined in the global scope, outside of any function. When a variable is declared as global, it can be accessed and modified from any part of the program, including within functions.&lt;/p&gt;

&lt;p&gt;Consider the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;my_function&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;global&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: 20
&lt;/span&gt;
&lt;span class="nf"&gt;my_function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# Output: 20
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a global variable x with an initial value of 10. Inside the function my_function(), we declare x as a global variable using the global keyword. We then assign a new value of 20 to x and print it, resulting in the output of 20. The change made to the global variable inside the function is reflected throughout the program, as seen by the subsequent print statement outside the function.&lt;/p&gt;

&lt;p&gt;The global keyword enables us to access and modify variables in the global scope from within functions. It provides a way to work with global variables while maintaining their values across different parts of the program.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;The nonlocal keyword is used to access and modify variables in an outer (non-local) function scope, particularly within nested functions. It allows us to communicate and share data between the inner and outer functions.&lt;/p&gt;

&lt;p&gt;On the other hand, the global keyword is used to access and modify variables in the global scope, outside of any function. It enables us to work with global variables and maintain their values across different parts of the program.&lt;/p&gt;

</description>
      <category>python</category>
      <category>global</category>
      <category>nonlocal</category>
    </item>
    <item>
      <title>Deploy a Smart Contract with Ethers.js</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Wed, 03 Nov 2021 18:56:24 +0000</pubDate>
      <link>https://dev.to/yosi/deploy-a-smart-contract-with-ethersjs-28no</link>
      <guid>https://dev.to/yosi/deploy-a-smart-contract-with-ethersjs-28no</guid>
      <description>&lt;p&gt;In order to create a new contract we need to send a transaction to the Ethereum blockchain with a payload that contains the compiled contract code. The transaction recipient must be set to null.&lt;/p&gt;

&lt;p&gt;The following JS code implements such a transaction using Ethers.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ethers&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;fs&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Deploy the contract to Ethereum test network - Ropsten&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDefaultProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ropsten&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Use your wallet's private key to deploy the contract&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;privateKey&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;YOUT_PRIVATE_KEY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Wallet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;privateKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="c1"&gt;// Read the contract artifact, which was generated by Remix&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;contract.json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;

  &lt;span class="c1"&gt;// Set gas limit and gas price, using the default Ropsten provider&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;formatUnits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getGasPrice&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gwei&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;gasLimit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;100000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;gasPrice&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parseUnits&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;gwei&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;

  &lt;span class="c1"&gt;// Deploy the contract&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;factory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ContractFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;abi&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bytecode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wallet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;contract&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;factory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;deployed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Deployment successful! Contract Address: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;contract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;})()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the transaction is successful, you’ll get the following message –&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Deployment successful! Contract Address: YOUR_CONTRACT_ADDRESS
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congrats for deploying your first contract! 🚀🚀🚀&lt;/p&gt;

</description>
      <category>ethereum</category>
      <category>ethersjs</category>
      <category>smartcontract</category>
      <category>web3</category>
    </item>
    <item>
      <title>Set Python3 as a default on MacOS</title>
      <dc:creator>yosi</dc:creator>
      <pubDate>Fri, 29 Oct 2021 17:14:15 +0000</pubDate>
      <link>https://dev.to/yosi/set-python3-as-a-default-on-macos-516i</link>
      <guid>https://dev.to/yosi/set-python3-as-a-default-on-macos-516i</guid>
      <description>&lt;p&gt;Download the and install the latest stable release from &lt;a href="https://www.python.org/downloads/macos/"&gt;python.org&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To set the release as default -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo ln&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 /usr/local/bin/python
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check it worked, open a &lt;strong&gt;new&lt;/strong&gt; terminal window and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll get -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Python 3.10.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>python</category>
      <category>macos</category>
    </item>
  </channel>
</rss>
