<?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>Forem: Sanchit Balchandani</title>
    <description>The latest articles on Forem by Sanchit Balchandani (@inovizz).</description>
    <link>https://forem.com/inovizz</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%2F487201%2Fe1ba4e9e-e513-4d45-a1a3-1184dd6e762e.jpeg</url>
      <title>Forem: Sanchit Balchandani</title>
      <link>https://forem.com/inovizz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/inovizz"/>
    <language>en</language>
    <item>
      <title>Harnessing AWS Glue for High-Volume JSON Processing 🚀</title>
      <dc:creator>Sanchit Balchandani</dc:creator>
      <pubDate>Thu, 25 May 2023 20:29:31 +0000</pubDate>
      <link>https://forem.com/epam_india_python/harnessing-aws-glue-for-high-volume-json-processing-gdl</link>
      <guid>https://forem.com/epam_india_python/harnessing-aws-glue-for-high-volume-json-processing-gdl</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In today's data-driven world 🌐, managing and interpreting substantial amounts of data has become increasingly vital. We often encounter scenarios where JSON files flood our AWS S3 buckets, demanding efficient processing. In this blog, I will share a recent use case where I successfully used AWS Glue, Python, and Terraform(mainly to handle infra) to tackle the challenge of processing a deluge of small JSON files efficiently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Background:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data handling at scale can be an arduous task, especially when dealing with a continuous influx of JSON files. I was asked to process approximately 1 million small JSON files per hour which are landing into an s3 bucket! 🕰️ These files needed to be transformed into larger, more manageable XML files for further analysis by another application. To address this demanding task, I leveraged the power of AWS Glue and other technologies to create a robust and scalable data processing pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tech Stack:&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Terraform for creating AWS Resources 🏗️&lt;br&gt;
Glue, S3, Systems Manager, Cloud Watch services from AWS 🛠️&lt;br&gt;
Python for writing the Glue Scripts 🐍&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Overcoming the Small Files Problem with Glue:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first hurdle I encountered was the infamous "Small Files Problem" within AWS Glue. This challenge arises when the Spark driver in AWS Glue is overwhelmed with list() method calls to S3, leading to memory exhaustion and, unfortunately, job failures. The first iteration of my solution ran for 6 hours and, you guessed it, failed due to a memory error. 😅&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HB2V1k2e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1l71k73l5vcghr4a9ydj.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HB2V1k2e--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1l71k73l5vcghr4a9ydj.jpg" alt="S3 small file issue" width="250" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To combat this issue, I devised a primary Glue job written in Python, leveraging PySpark and Boto3. This job merged multiple small JSON files into larger ones based on a configurable parameter, mitigating the Small Files Problem. It also optimized downstream processing by partitioning the merged files into date-based folders within the S3 bucket. I saved the files in the following format:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;YYYYMMDD/HHMM&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This approach helped me run this partition job multiple times per day, partitioning files based on specific hours. This made the main transformation job, running at midnight, more efficient as it dealt with fewer files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transforming and Optimizing Data Processing:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The secondary, or main, Glue job was designed to initialize a Spark session and fetch essential parameters like batch size and date from the AWS Systems Manager (SSM) Parameter Store. This job processed the JSON files in batches using Spark's inherent capabilities. I used the popular Python library xml.etree.ElementTree to convert JSON data into the desired XML format. To optimize storage and write performance, the transformed data was compressed using gzip before being written back to the S3 bucket.&lt;/p&gt;

&lt;p&gt;Here is the high-level architecture&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9HecFcaz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s39elus94hulkzemnccx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9HecFcaz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s39elus94hulkzemnccx.png" alt="architecture diagram" width="621" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fruitful Outcome:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The result? A super-efficient pipeline that processed approximately 70k files in less than 2.5 minutes! 🚀 This feat required 10 Data Processing Units (DPUs) in AWS Glue. However, the solution is scalable and can accommodate additional DPUs to meet future requirements. With the current setup, it can easily process 1 million JSON files in around 35 mins which is quite fast and seems scalable as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaway:&lt;/strong&gt; The Power of Synergistic Tools and Strategies&lt;/p&gt;

&lt;p&gt;The experience of using AWS Glue, Python, and Terraform to handle large amounts of JSON data highlights the significance of using the right combination of tools and strategies to address big data challenges successfully. As data keeps growing rapidly, AWS Glue offers a reliable platform for creating strong data processing pipelines. Python's flexibility allows for intricate data transformations, and Terraform helps optimize infrastructure efficiency. By leveraging these synergistic tools and strategies, you can effectively tackle the complexities of big data processing.  🏗️👏&lt;/p&gt;

&lt;p&gt;P.S. - Thanks to generative AI for the edits ;) and making my English look better. The use case is real though :D&lt;/p&gt;

</description>
      <category>aws</category>
      <category>glue</category>
      <category>awsglue</category>
      <category>s3</category>
    </item>
    <item>
      <title>Building Strong Bonds with Your Engineering Team(s)</title>
      <dc:creator>Sanchit Balchandani</dc:creator>
      <pubDate>Fri, 10 Feb 2023 19:21:20 +0000</pubDate>
      <link>https://forem.com/inovizz/building-strong-bonds-with-your-engineering-teams-3g8p</link>
      <guid>https://forem.com/inovizz/building-strong-bonds-with-your-engineering-teams-3g8p</guid>
      <description>&lt;p&gt;While leading a decent-sized team for the last 2 years or so, I have learned the importance of building strong relationships with my team members. In my experience, managing a decently big team requires a lot of effort, patience, and the right approach. In this article, I would like to share some of the strategies I have used that have been effective for me and my team. These approaches are based on my own personal experience and I believe they can work well for others, although every leader has their own unique approach. I prefer staying connected with my team and these strategies have worked well for me. Please feel free to offer criticism and share your feedback(if any).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Respect the Skill&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most important things I have learned as a leader is to respect the skill, not particularly the seniority level. It doesn't matter if someone is junior to me, but if they have higher skills, they have my immense respect. This has helped to build trust and credibility with my team members, and they have become more confident in their abilities. When there are such cases, I don't shy to tell them upfront about this. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hiring for Competence&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When hiring for any position, I look for someone who is more skilled than my current team members. If I need to hire someone at my level, I'll make sure to find someone even more skilled than myself. This is because I think it's important to surround ourselves with people who are more knowledgeable and capable than we are. That way, we can learn from them and they can help us grow as leaders. "Skills and experience are important." &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trusting Your Team&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the most important things a leader can do is to trust their team. When you trust your team members, you give them the confidence to perform at their best. Even if someone has failed once or twice, if you continue to trust them and vouch for them, it can push them to do even better. I've seen this happening in real-time and people do well even if they have some mental support from their leader. In today's rush, we kinda miss these things, but this sort of trust can go a long way in building a strong and motivated team.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Being Empathetic&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Being an empathetic leader is crucial to building strong relationships with your team members. Work is not just about getting the job done, it's also about how you are being treated. As a leader, it's important to remain empathetic towards all of your associates and to encourage them to do the same. Not everyone might follow, but if you as a leader set the bar right, it becomes the culture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reward Often&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Rewarding and recognizing your team members often can give them a lot of motivation. Whether it's a simple thank you or more formal recognition in email, this can help to boost morale and increase job satisfaction. I sometimes feel that I kind of miss out on appreciating people and in fact got this feedback from someone that I missed appreciating him for some good work done. So it's evident that your peers would love even the smallest of appreciation. So, don't hesitate to recognize people and also don't miss out on appreciating your low performers, they need it the most :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giving Ownership&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When assigning tasks to your team members, it's important to give them a sense of ownership. This means giving them tasks that they can lead and make their own. By doing this, you are giving them the opportunity to showcase their skills and take ownership of their work. I always believe that once you identify the potential in a person and sense even a minimal potential to take ownership, make them feel responsible and give them full ownership of the task/program. At the start, you might need to just oversee but in most cases, they will do beautifully well and you'll feel awesome about their achievements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimizing Interventions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;it's important to minimize your interventions when your team members are leading processes. You should just oversee their work to make sure everything is running smoothly, but avoid micromanaging. This gives your team members the space and freedom they need to take their work to the next level. Otherwise, it's more or less the same you are executing on your own terms and your peers are just helping you run the show. So, be all ears to their ideas and let them implement them with some validations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Succession Plan&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a leader, it's important to make sure you don't slow down your team's progress. This means sharing your responsibilities and making sure someone else knows what you do. This way, you can build a stronger team that trusts each other and works well together.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quality Over Quantity&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When it comes to team development, it's important to focus on quality rather than quantity. A team of let's say, N+ members could be a big achievement, but it's more important to have a team that is high-performing, motivated, and skilled. By focusing on quality building (like asking your team members to develop new skills), you are investing in the long-term success of your team and ensuring that they are equipped to meet new challenges that might come their way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Open Communication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finally, being open and transparent with your associates is crucial to building a strong and successful team. Whether it's about salary, the quality of work, or any other concerns, it's important to be open and to set up a transparent culture. This makes things easier for everyone, and it helps to build trust and credibility with your team members. Some folks, might not like it but it is okay you need to think from a perspective of a person who wants very transparent, open and detailed communication because that's how you'll make them feel connected and bring transparency.&lt;/p&gt;

&lt;p&gt;In conclusion, managing a large team can be very challenging, but with the right approach, it can also be one of the most wonderful experiences of your career. These approaches make you more human and well-connected with your team, it creates a bond and I strongly feel such teams can achieve much more.&lt;/p&gt;

</description>
      <category>debian</category>
      <category>android</category>
      <category>linux</category>
    </item>
    <item>
      <title>Elevating Your Serverless Development with AWS SAM</title>
      <dc:creator>Sanchit Balchandani</dc:creator>
      <pubDate>Sun, 22 Jan 2023 17:34:33 +0000</pubDate>
      <link>https://forem.com/inovizz/elevating-your-serverless-development-with-aws-sam-kdj</link>
      <guid>https://forem.com/inovizz/elevating-your-serverless-development-with-aws-sam-kdj</guid>
      <description>&lt;p&gt;IAC is essential for modern day development as it allows for more efficient and effective management of infrastructure. It helps to automate the provisioning and deployment of resources, and enables software engineers to manage their infrastructure as code in a version control system. This allows for better collaboration and tracking of changes, making it easier to rollback or update resources as needed.&lt;/p&gt;

&lt;p&gt;I've been working on Terraform for a bit now, but never had a chance to explore much about SAM which can easily let you deploy AWS serverless resources using CloudFormation. So I thought of picking up on AWS SAM and explore why it is so good. So in this blog, I tried giving some context about AWS SAM and why it is useful and also sharing one sample use-case which I tried recently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AWS Serverless Application Model&lt;/strong&gt; a.k.a AWS SAM is an open-source tool that allows software engineers to define their serverless infrastructure as code, making it easy to manage, test, and deploy their applications. It also comes with a CLI which can be used to deploy &amp;amp; manage serverless applications on AWS.&lt;/p&gt;

&lt;p&gt;One of the main benefits of using SAM is that it simplifies the process of creating and deploying serverless applications. With SAM, we can use a simple YAML or JSON template to define the resources that their application needs, such as Lambda functions, API Gateway, and DynamoDB tables. SAM then takes care of creating and deploying these resources to AWS, making the process much easier and more efficient than doing it manually.&lt;/p&gt;

&lt;p&gt;Another benefit of using SAM is that it provides a consistent development experience across different languages and frameworks. SAM supports multiple languages, including Python, Node.js, and Go, and it can be used with different frameworks, such as Flask, Express, and Django. This means that we can use the same template and CLI commands to deploy the applications, regardless of the language.&lt;/p&gt;

&lt;p&gt;To get started with SAM, we need to install the SAM CLI on the local machine. The SAM CLI can be installed using the pip package manager 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;pip &lt;span class="nb"&gt;install &lt;/span&gt;aws-sam-cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the SAM CLI is installed, we can use it to create a new application template 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;sam init &lt;span class="nt"&gt;--runtime&lt;/span&gt; &amp;lt;runtime&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where  is the language and version that the application will be written in, such as nodejs12.x or python3.8. This command will create a new directory with a basic template that includes a Lambda function and an API Gateway.&lt;/p&gt;

&lt;p&gt;To deploy the application to AWS, we can use the sam deploy command. This command will create or update the resources defined in the template, and it will also create an S3 bucket to store the application's artifacts. To deploy the application, we need to run 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;sam deploy &lt;span class="nt"&gt;--stack-name&lt;/span&gt; &amp;lt;stack-name&amp;gt; &lt;span class="nt"&gt;--capabilities&lt;/span&gt; CAPABILITY_IAM
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;&amp;lt;stack-name&amp;gt;&lt;/code&gt; is the name of the CloudFormation stack that will be created. The &lt;code&gt;--capabilities CAPABILITY_IAM&lt;/code&gt; flag is required to create IAM resources, such as roles and policies, that are defined in the template.&lt;/p&gt;

&lt;p&gt;Let's do a small demo now!&lt;/p&gt;

&lt;p&gt;Below is an example of using SAM to deploy a simple Python application on AWS. The application consists of a Lambda function that handles a GET request to an API Gateway endpoint, which retrieves data from a DynamoDB table. Above commands while explaining SAM were just for reference, to build the demo please start using commands from here on -&lt;/p&gt;

&lt;p&gt;First, we will create a new directory for our application and initialize it with the SAM CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sam init &lt;span class="nt"&gt;--runtime&lt;/span&gt; python3.8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After running above command, it will ask you some questions, please choose &lt;code&gt;1&lt;/code&gt; to select &lt;code&gt;AWS Quick Start Templates&lt;/code&gt; and then subsequently choose &lt;code&gt;1&lt;/code&gt; to select &lt;code&gt;Hello World Example&lt;/code&gt; and when you are asked for app name, type it as &lt;code&gt;demo-app-sam&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This will create a new directory with the basic template files, including &lt;code&gt;template.yaml&lt;/code&gt; and &lt;code&gt;hello_world&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;Next, we will create a new directory &lt;code&gt;demo&lt;/code&gt; and create a new file called &lt;code&gt;app.py&lt;/code&gt; this file will contain our Lambda function code:&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;mkdir &lt;/span&gt;demo
&lt;span class="nb"&gt;touch &lt;/span&gt;demo/app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in our &lt;code&gt;app.py&lt;/code&gt; file, we will import the necessary modules like &lt;code&gt;json&lt;/code&gt;, including &lt;code&gt;boto3&lt;/code&gt; to interact with &lt;code&gt;DynamoDB&lt;/code&gt;, and write a function named &lt;code&gt;handler&lt;/code&gt; that will handle the GET request to the API Gateway endpoint, and retrieve data from the DynamoDB table:&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;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;dynamodb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;resource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;dynamodb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;table&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;dynamodb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;demo-table&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;scan&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;statusCode&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Items&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;headers&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Content-Type&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&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;p&gt;Now we will update our template.yaml to include the resources needed for our application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;AWSTemplateFormatVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;2010-09-09'&lt;/span&gt;
&lt;span class="na"&gt;Transform&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Serverless-2016-10-31&lt;/span&gt;
&lt;span class="na"&gt;Description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="s"&gt;demo-app-sam&lt;/span&gt;

  &lt;span class="s"&gt;Sample SAM Template for demo-app-sam&lt;/span&gt;

&lt;span class="na"&gt;Globals&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;Function&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;
    &lt;span class="na"&gt;MemorySize&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;128&lt;/span&gt;
    &lt;span class="na"&gt;Tracing&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Active&lt;/span&gt;
  &lt;span class="na"&gt;Api&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;TracingEnabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

&lt;span class="na"&gt;Resources&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;DemoFunction&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::Serverless::Function&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;CodeUri&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;demo/&lt;/span&gt;
      &lt;span class="na"&gt;Handler&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;app.handler&lt;/span&gt;
      &lt;span class="na"&gt;Runtime&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;python3.8&lt;/span&gt;
      &lt;span class="na"&gt;Policies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;DynamoDBCrudPolicy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;TableName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;demo-table&lt;/span&gt;
      &lt;span class="na"&gt;Architectures&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;x86_64&lt;/span&gt;
      &lt;span class="na"&gt;Events&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;DemoApi&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Api&lt;/span&gt;
          &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;Path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/&lt;/span&gt;
            &lt;span class="na"&gt;Method&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;get&lt;/span&gt;
  &lt;span class="na"&gt;DemoTable&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;Type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;AWS::DynamoDB::Table&lt;/span&gt;
    &lt;span class="na"&gt;Properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;TableName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;demo-table&lt;/span&gt;
      &lt;span class="na"&gt;AttributeDefinitions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;AttributeName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;id&lt;/span&gt;
          &lt;span class="na"&gt;AttributeType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;S&lt;/span&gt;
      &lt;span class="na"&gt;KeySchema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;AttributeName&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;id&lt;/span&gt;
          &lt;span class="na"&gt;KeyType&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;HASH&lt;/span&gt;
      &lt;span class="na"&gt;ProvisionedThroughput&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;ReadCapacityUnits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
        &lt;span class="na"&gt;WriteCapacityUnits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This template defines a Lambda function named DemoFunction that is triggered by a GET request to the &lt;code&gt;/&lt;/code&gt;endpoint of an API Gateway. It also defines a DynamoDB table named &lt;code&gt;demo_table&lt;/code&gt; with a single id field.&lt;/p&gt;

&lt;p&gt;Finally, to deploy our application, we will run 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;sam deploy &lt;span class="nt"&gt;--stack-name&lt;/span&gt; demo-app-sam &lt;span class="nt"&gt;--capabilities&lt;/span&gt; CAPABILITY_IAM &lt;span class="nt"&gt;--guided&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create or update the resources defined in the template, including the Lambda function, API Gateway, and DynamoDB table. Once the deployment is complete, we can test our application by sending a GET request to the API Gateway endpoint, which should return data from the DynamoDB table.&lt;/p&gt;

&lt;p&gt;In this example, we have demonstrated how to use SAM to deploy a Python application on AWS, which consist of a Lambda function that handles a GET request to an API Gateway endpoint, retrieves data from a DynamoDB table, and returns it to the client. &lt;/p&gt;

&lt;p&gt;Now to summarize, AWS SAM is a powerful tool for building and deploying serverless applications on AWS. It provides a simple and consistent way to define serverless infrastructure as code, making it easy to manage, test, and deploy applications. The SAM CLI also provides a convenient way to create and deploy applications to AWS, making the process much more efficient and streamlined. With the help of examples and code, we can easily understand the process and start building their own serverless applications on AWS.&lt;/p&gt;

&lt;p&gt;Feel free to reach out to &lt;a href="https://linktr.ee/inovizz" rel="noopener noreferrer"&gt;me&lt;/a&gt; if you have any questions, I'd be happy to chat.&lt;/p&gt;

&lt;p&gt;P.S. - Once you are done running and testing your demo, don't forget to delete the created resources from AWS ;)&lt;/p&gt;

&lt;p&gt;Use below command to do that -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;sam delete &lt;span class="nt"&gt;--stack-name&lt;/span&gt; demo-app-sam
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>discuss</category>
      <category>mentalhealth</category>
      <category>workplace</category>
      <category>career</category>
    </item>
    <item>
      <title>How to migrate Python 2 projects to 3 &amp; some useful tips</title>
      <dc:creator>Sanchit Balchandani</dc:creator>
      <pubDate>Tue, 12 Jan 2021 12:08:22 +0000</pubDate>
      <link>https://forem.com/epam_india_python/how-to-migrate-python-2-projects-to-3-some-useful-tips-1kid</link>
      <guid>https://forem.com/epam_india_python/how-to-migrate-python-2-projects-to-3-some-useful-tips-1kid</guid>
      <description>&lt;p&gt;Python 2.7 came to end of life in January 2020 and even before that lot of software migrations to Python 3 have been happening. However, I was a little late to the party and got to work on one such project in late 2020. So in this blog, I'll try and summarize what steps we followed and some of the tips which can be helpful for a fellow developer who may need to migrate a Python project in future. &lt;/p&gt;

&lt;p&gt;Before we get started, let me also add a small disclaimer, that I'll not be touching upon the differences of Python 2 &amp;amp; 3, there is a lot of content available on the internet for the same so please feel free to check it out.&lt;/p&gt;

&lt;p&gt;We'll be talking about the migration where we were not worried about Python2 compatibility because that was the case with us. However, I'll share some reference links for py2&amp;amp;3 compatible migrations as well. So let's get started and see what are the steps one can follow when migration to Python 3 is to be done. We migrated from Python 2.7 to 3.7 but the latest version is 3.9 so if you are confident enough to choose the latest Python version, you can do that as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps for migration
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The first step would be to understand some fundamental difference between Python 2 &amp;amp; 3, that will help fix issues&lt;/li&gt;
&lt;li&gt;Check the code coverage of the code and make sure that we have decent test coverage. The more the code coverage, the easier would be to migrate the code&lt;/li&gt;
&lt;li&gt;Set up a virtual environment for both Python2.7 and Python 3.7+ versions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Virtual Env for Python2&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python2.7 &lt;span class="nt"&gt;-m&lt;/span&gt;  pip &lt;span class="nb"&gt;install &lt;/span&gt;virtualenv
python2.7 &lt;span class="nt"&gt;-m&lt;/span&gt; virtualenv py27
&lt;span class="nb"&gt;source &lt;/span&gt;py27/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Virtual Env for Python3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python3.7 &lt;span class="nt"&gt;-m&lt;/span&gt; virtualenv py3
&lt;span class="nb"&gt;source &lt;/span&gt;py3/bin/activate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Also, do create a separate branch for Python 3 codebase and maintain these two versions parallelly unless the full migration is completed&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The next steps shall be to figure out the dependencies of the codebase compatible with Python 3, for that I'd recommend using the following tool&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://pypi.org/project/caniusepython3/"&gt;canisepython3&lt;/a&gt;: This helps to find out which existing dependencies are compatible with python3&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;caniusepython3
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href="https://pypi.org/project/pip-tools/"&gt;pip-tools&lt;/a&gt;: When we are migrating and we may also worried about pinning the dependencies &amp;amp; sub-deps then pip-tools is very handy, do explore it&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;pip-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once dependencies are sorted then run the test cases and find out the number of failures or any major issues, keep a note of test case failures, that will help you estimate the work up to some level&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After this, we need to move to the conversion of the code, so we already have some auto conversions tools available like &lt;a href="https://docs.python.org/3/library/2to3.html"&gt;2to3&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;In our case we used a library called &lt;a href="http://python-future.org/automatic_conversion.html"&gt;futurize&lt;/a&gt; which is also based on &lt;a href="https://docs.python.org/3/library/2to3.html"&gt;2to3&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;future
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;

&lt;p&gt;We can use below command to auto-convert the code to Python 3&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight shell"&gt;&lt;code&gt;futurize &lt;span class="nt"&gt;--stage1&lt;/span&gt; mypackage/&lt;span class="k"&gt;**&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;.py
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the code is auto-converted, run the test cases and check the number of failures and start fixing them&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the test cases are fixed, we can proceed with our functional testing, regression testing and CI pipeline upgrades&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note - While fixing the functional test cases, it will be handy to have both Python 2 &amp;amp; Python 3 version of apps running in two diff virtual envs, because then we can go back n forth between two versions and see the behaviour change if we are stuck with fixing a bug&lt;/p&gt;

&lt;h2&gt;
  
  
  Few Gotchas
&lt;/h2&gt;

&lt;p&gt;As it's mentioned in futurize library's documentation that its auto conversion output may not be fully accurate and it has some issues and bugs as well, so it is important for us to review the automated fixes before merging the code, so from our experience few things can be taken care:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Auto-conversion will end up adding list inbuilt function to all such cases where we might be using

&lt;code&gt;dict.iteritems()&lt;/code&gt;

, after the conversion it becomes

&lt;code&gt;list(dict.items())&lt;/code&gt;

because

&lt;code&gt;iteritems&lt;/code&gt;

returns a &lt;code&gt;list&lt;/code&gt; in Python 2.7 and in Python 3 it returns

&lt;code&gt;&amp;lt;class 'dict_items'&amp;gt;&lt;/code&gt;

. However, It is an unnecessary call because conversion to list takes time and you can still iterate through

&lt;code&gt;dict.items()&lt;/code&gt;

the same way you do over the converted list&lt;/li&gt;
&lt;li&gt;Futurize can also add a lot of unused imports to your codebase, we can get rid of them if we are not worried about backward compatibility, but be mindful of not removing all unused import and do check and analyze the module before doing it&lt;/li&gt;
&lt;li&gt;If you might have used zip function in Python 2.7 and then tried converting it to dict then futurize might wrap &lt;code&gt;zip&lt;/code&gt; with a &lt;code&gt;list&lt;/code&gt; function call, you won't need that &lt;code&gt;list()&lt;/code&gt; function call in most cases after migrating to Python 3
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;all_vals &lt;span class="o"&gt;=&lt;/span&gt; dict&lt;span class="o"&gt;(&lt;/span&gt;list&lt;span class="o"&gt;(&lt;/span&gt;zip&lt;span class="o"&gt;(&lt;/span&gt;array1, array2&lt;span class="o"&gt;)))&lt;/span&gt; &lt;span class="c"&gt;# Unnecessary list function call&lt;/span&gt;
all_vals &lt;span class="o"&gt;=&lt;/span&gt; dict&lt;span class="o"&gt;(&lt;/span&gt;zip&lt;span class="o"&gt;(&lt;/span&gt;array1, array2&lt;span class="o"&gt;))&lt;/span&gt; &lt;span class="c"&gt;# Correct&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Relative imports are no longer supported in Python 3. Any code that used relative imports in Python 2 now has to be modified to support absolute imports&lt;/li&gt;
&lt;li&gt;In Python2, &lt;code&gt;CSV&lt;/code&gt; files should be opened in binary mode. but, in Python 3, the files are to be opened in the text mode&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Error Fixes
&lt;/h2&gt;

&lt;p&gt;So during the migration, we may end up fixing some very basic level errors which may get introduced because of futurize or because of the Python 2 &amp;amp; 3 differences. So I'm listing few of them which we faced and that might help you to quickly get rid of those -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The old division would not work in Python3, and we can fix such cases like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;from past.utils import old_div
x &lt;span class="o"&gt;=&lt;/span&gt; y / 1000 &lt;span class="c"&gt;# Would give unexpected result in Python 3 and existing test case may fail because of this&lt;/span&gt;
x &lt;span class="o"&gt;=&lt;/span&gt; old_div&lt;span class="o"&gt;(&lt;/span&gt;y, 1000&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# This would result as Python 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In all exception handling cases, we might end up getting this common error, wherein Python 2 we had an attribute called message for the exception class and python 3 doesn't have it
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Old case&lt;/span&gt;
except Exception as e:
    raise CustomError&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"message: {}"&lt;/span&gt;.format&lt;span class="o"&gt;(&lt;/span&gt;e.message&lt;span class="o"&gt;))&lt;/span&gt;

&lt;span class="c"&gt;# How to fix&lt;/span&gt;
except Exception as e:
    raise CustomError&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;message&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"message: {}"&lt;/span&gt;.format&lt;span class="o"&gt;(&lt;/span&gt;e&lt;span class="o"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For the same exception handling errors when we remove message attribute from the

&lt;code&gt;e&lt;/code&gt;

variable than in some case we might face below error where we will do concat operation on

&lt;code&gt;e&lt;/code&gt;

and some string, that will cause a failure
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Failure case&lt;/span&gt;
try:
    1/0
except Exception as e:
    print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"custom_message"&lt;/span&gt;+e&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# This would give an error&lt;/span&gt;
&lt;span class="c"&gt;# How to fix&lt;/span&gt;
try:
    1/0
except Exception as e:
    print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"custom_message"&lt;/span&gt;+str&lt;span class="o"&gt;(&lt;/span&gt;e&lt;span class="o"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;hasattr(dict, 'iteritems')&lt;/code&gt; would return &lt;code&gt;False&lt;/code&gt; in Python 3, to fix please use this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hasattr&lt;span class="o"&gt;(&lt;/span&gt;dict,&lt;span class="s1"&gt;'items’) 
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In Python 2 we used to use

&lt;code&gt;string.replace()&lt;/code&gt;

as well in somecases to replace string within a string, that will not work in Python 3, hence fix it like this -
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;a &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"asdfghj"&lt;/span&gt;
string.replace&lt;span class="o"&gt;(&lt;/span&gt;a, &lt;span class="s2"&gt;"asd"&lt;/span&gt;, &lt;span class="s2"&gt;"xcv"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# Will not work&lt;/span&gt;
a.replace&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"asd"&lt;/span&gt;, &lt;span class="s2"&gt;"xcv"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="c"&gt;# correct&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cmp()&lt;/code&gt; function which used to be available in Python 2 is not available in Python 3, so you might need to implement something like this to fix the errors -
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;def cmp&lt;span class="o"&gt;(&lt;/span&gt;a, b&lt;span class="o"&gt;)&lt;/span&gt;:
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;a &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; b&lt;span class="o"&gt;)&lt;/span&gt; - &lt;span class="o"&gt;(&lt;/span&gt;a &amp;lt; b&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;I hope this information was helpful for you and I also hope that this may expedite your migration time. Overall, I must also confess that even though migrations steps seems kind of pretty straight forward but the whole process can be tiring because of fixing some common errors again and again. If you are able to fix these small errors quickly then you can focus on the functional part of the migration which is most important. So which is why I tried to list some of the common issues I faced during the migration, hope it can be useful for someone. Thanks for reading and feel free to share any feedback in the comment section.&lt;/p&gt;

&lt;h4&gt;
  
  
  References:
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://wiki.openstack.org/wiki/Python3#Port_Python_2_code_to_Python_3"&gt;https://wiki.openstack.org/wiki/Python3#Port_Python_2_code_to_Python_3&lt;/a&gt;&lt;br&gt;
&lt;a href="http://python3porting.com/"&gt;http://python3porting.com/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.python.org/dev/howto/pyporting.html"&gt;https://docs.python.org/dev/howto/pyporting.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://python-future.org/quickstart.html"&gt;https://python-future.org/quickstart.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://python-future.org/quickstart.html#to-convert-existing-python-2-code"&gt;https://python-future.org/quickstart.html#to-convert-existing-python-2-code&lt;/a&gt; (On python 2 compatibility)&lt;/p&gt;

&lt;p&gt;Disclaimer: This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.&lt;/p&gt;

</description>
      <category>python</category>
      <category>python3</category>
      <category>migration</category>
      <category>2to3</category>
    </item>
    <item>
      <title>Why do Software Developers need to be More Empathetic?</title>
      <dc:creator>Sanchit Balchandani</dc:creator>
      <pubDate>Thu, 24 Dec 2020 00:09:39 +0000</pubDate>
      <link>https://forem.com/inovizz/why-do-software-developers-need-to-be-more-empathetic-27m</link>
      <guid>https://forem.com/inovizz/why-do-software-developers-need-to-be-more-empathetic-27m</guid>
      <description>&lt;p&gt;We all know about "Empathy" and especially during these unprecedented times, we might have heard this term even more often. However, do we really practice and understand the real importance of Empathy in our life? &lt;/p&gt;

&lt;p&gt;In my little experience and the number of people I've met during my career, most of us understand the importance of it but very few would practice it in real life because sometimes even if you know what's right or wrong, you may follow your subconscious mind and end up being unempathetic in that moment.&lt;/p&gt;

&lt;p&gt;In this blog, I'll try and convince you why do software developers and in general, we need to be more thoughtful about being Empathetic. &lt;/p&gt;

&lt;p&gt;Also, before we move forward let me clarify a quick point - &lt;strong&gt;"Sympathy is not Empathy!"&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.pinimg.com%2Foriginals%2F96%2F9b%2F38%2F969b381ff32dfde3201a3179e7e7210b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fi.pinimg.com%2Foriginals%2F96%2F9b%2F38%2F969b381ff32dfde3201a3179e7e7210b.jpg" alt="Sympathy-Empathy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sympathy is more about feeling sorry for someone. However, Empathy is about actually understanding someone else's pain/suffering. In case of being sympathetic, you'd probably feel for that person at that moment and move on, but empathy doesn’t work the same way. it opens the door to a range of long-lasting emotions and feelings.&lt;/p&gt;

&lt;p&gt;Now let's come back to the importance of Empathy for a Software Developer.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Software Developer&lt;/strong&gt; is a generic term or title and I assume that software developers play different roles in their organizations - Business Analysis, Coding, Testing, Leadership, DevOps, Maintenance etc. Each of these roles would involve talking to people and wherever you need to deal with people, empathy can play a key role. It can help you create better client relations, create better products, retain employees &amp;amp; help you build a great team. We can go into the depth of each of these roles and probably try to understand the importance but let's not go the orthodox way and instead, I'll add few pointers from my experience which may be limited to certain roles but in general applicable to most of the cases.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Working with a fellow associate&lt;/strong&gt; - A lot of time when you go up the ladder or let's say if you are super skilful, and you are working with someone who may not be equally skilful; that shouldn't allow you think or develop some subconscious bias about that person - e.g. He/she is not good or he/she is taking too long to finish the task or he/she is giving me excuses. Because if you do that, your subconscious mind may not let you experience that person's actual state or condition. That's where Empathy plays a very important role. If you are a fellow developer or a lead and if you practice being empathetic, you can create a better work environment for that person and also help him/her grow eventually. Note - arrogance &amp;amp; rudeness are disproportional of Empathy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;While taking an Interview&lt;/strong&gt; - When you take an interview, Empathy also can play a great role for the interviewer to identify the candidate's potential. With this, I don't mean that one shall become empathetic and hire a candidate which doesn't fulfil the criteria. However during the interview, If you can be kind enough, give decent time to the candidate even if he/she is not doing well can do wonders. It is generally the interviewers' responsibility to get the best out of the candidate and it will only happen when you'll show empathy towards the candidate. Sometimes if you find candidate very nervous, you may have to play dumb and that eventually can make him/her feel comfortable. If you are able to achieve that by being little empathetic then it certainly creates a great experience for both interviewer and the candidate. And who knows you'll end up hiring a great team player :D &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;During the customer Interactions&lt;/strong&gt; - This is more of an obvious one because customer interactions are generally tricky and can be complicated at times for software developers. We(software devs) tend to think more from a software endpoint but if the customer is non-technical then it can be a nightmare as well. I've seen a lot of back n forths happening because of small communication gaps, it can be frustrating for both sides. The simple solution is when you go to these discussions try and be empathetic, this might enable you to think from a customer standpoint and when gradually both parties start to think in same directions, there are always possibilities of lesser conflicts and unneeded iterations.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Finovizz%2Finovizz.github.io%2Fblob%2Fmaster%2FWhatsApp%2520Image%25202020-12-24%2520at%252007.13.19.jpeg%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Finovizz%2Finovizz.github.io%2Fblob%2Fmaster%2FWhatsApp%2520Image%25202020-12-24%2520at%252007.13.19.jpeg%3Fraw%3Dtrue" alt="Leaders"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;If you are a leader&lt;/strong&gt; - Empathy is a must-have quality in the modern-day industry leaders and many companies are focusing on these qualities as well while hiring them. If you are a leader &amp;amp; Empathetic -&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; You will be able to better understand the needs of those people who you work &amp;amp; deal with&lt;/li&gt;
&lt;li&gt;You will experience the world in a bigger perspective as you perceive through not only your perspective but of those around you as well&lt;/li&gt;
&lt;li&gt;Also, You will learn how to motivate the people around you and help them grow&lt;/li&gt;
&lt;li&gt;You will be able to more effectively convince others of your point of view&lt;/li&gt;
&lt;li&gt;Moreover, you will be a better leader, and most importantly, a better friend.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;How to practice it?&lt;/strong&gt; - If you are reading till this point, I hope it is evident and clear that empathy is not only a feeling but a very much needed skill in today's software developer's profile :) and any skill can be learned and practised.&lt;/p&gt;

&lt;p&gt;So being mindful about your daily interactions, be it with anyone in your office or personal life can help you learn and practice this. I generally prefer to re-think some of my conversations and If I feel I could have been better then I try not to repeat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt; - I hope that I was able to convince you that Empathy is critically very important. Considering that title of the blog is about the importance of empathy for a software developer, so I'd like to conclude mentioning that companies are trying to build practices, engineering excellence cultures, adopting a lot of software best practice to grow exponentially but not greatly focusing making Empathy a must-have skill. Also, these days leaders are trying to adopt the "trust culture" within engineering teams. However, I strongly feel trust is the output of Empathy :) &lt;/p&gt;

&lt;p&gt;So looking at all the points I mentioned in the blog above, I feel times have changed and Empathy should be given a lot of value as a skillset and there shall be efforts to train engineers about it.&lt;/p&gt;

&lt;p&gt;With that, I'd like to end this blog here, hope you liked it. Do reach out to me if you have any questions or suggestions or inputs.&lt;/p&gt;

&lt;p&gt;I'm available at &lt;a href="https://twitter.com/inovizz" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://linkedin.com/in/inovizz/" rel="noopener noreferrer"&gt;Linkedin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Disclaimer: This is a personal [blog, post, statement, opinion]. The views and opinions expressed here are only those of the author and do not represent those of any organization or any individual with whom the author may be associated, professionally or personally.&lt;/p&gt;

</description>
      <category>softwaredeveloper</category>
      <category>life</category>
      <category>empathy</category>
      <category>sympathy</category>
    </item>
  </channel>
</rss>
