<?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: vybhav72954</title>
    <description>The latest articles on DEV Community by vybhav72954 (@vybhav).</description>
    <link>https://dev.to/vybhav</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%2F534169%2F6125ed4b-0376-47ea-b586-382da0085687.jpeg</url>
      <title>DEV Community: vybhav72954</title>
      <link>https://dev.to/vybhav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vybhav"/>
    <language>en</language>
    <item>
      <title>Let's talk about Sys</title>
      <dc:creator>vybhav72954</dc:creator>
      <pubDate>Mon, 24 May 2021 12:45:41 +0000</pubDate>
      <link>https://dev.to/vybhav/let-s-talk-about-sys-25mf</link>
      <guid>https://dev.to/vybhav/let-s-talk-about-sys-25mf</guid>
      <description>&lt;p&gt;Everybody loves Python (Trust me, everybody does). But &lt;em&gt;why&lt;/em&gt;? An &lt;strong&gt;intuitive&lt;/strong&gt;, &lt;strong&gt;simple&lt;/strong&gt;, yet &lt;strong&gt;highly scalable&lt;/strong&gt; language, Python is a &lt;em&gt;dynamically typed&lt;/em&gt;, &lt;em&gt;interpreted language&lt;/em&gt;. However, we will not dive into the nitty-gritty of Python's properties but will instead focus on the functionality of the interpreter of Python.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sys&lt;/code&gt; module in Python provides information about constants, functions, and methods of the Python interpreter. Moreover, it also provides access to multiple variables under the command of the interpreter and their associated methods. So basically &lt;code&gt;sys&lt;/code&gt; module allows one to operate over the interpreter, so what, is it useful?&lt;/p&gt;

&lt;p&gt;Let's talk about some interesting use cases of &lt;code&gt;sys&lt;/code&gt; module.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;But first of all, how to access the &lt;code&gt;sys&lt;/code&gt; module?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sys&lt;/code&gt; is part of &lt;code&gt;Python 3.x&lt;/code&gt; Standard Library, so no separate installation is required.&lt;/p&gt;

&lt;p&gt;Just &lt;code&gt;import&lt;/code&gt; it and you are good to go.&lt;/p&gt;

&lt;p&gt;To verify &lt;code&gt;sys&lt;/code&gt;, let's start by checking its version.&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="c1"&gt;# Imports
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Viola! It's working. For more information about sys and its license, run &lt;code&gt;sys.copyright&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Usage
&lt;/h3&gt;

&lt;p&gt;Let's start with some basic use cases of &lt;code&gt;sys&lt;/code&gt; module.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.maxsize&lt;/code&gt; returns the max value that an int variable can hold.
&lt;/li&gt;
&lt;/ul&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="nn"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maxsize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;9223372036854775807
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.path&lt;/code&gt; returns a list containing all the paths to all the Python Modules and the interpreter in the running environment.
&lt;/li&gt;
&lt;/ul&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="nn"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;['C:\\Users\\asus\\PycharmProjects\\Auto_Caption_Generator', 'C:\\Users\\asus\\PycharmProjects\\Auto_Caption_Generator', 'C:\\Program Files\\JetBrains\\PyCharm 2020.3.3\\plugins\\python\\helpers\\pycharm_display', 'C:\\Users\\asus\\AppData\\Local\\Programs\\Python\\Python38\\python38.zip', 'C:\\Users\\asus\\AppData\\Local\\Programs\\Python\\Python38\\DLLs', 'C:\\Users\\asus\\AppData\\Local\\Programs\\Python\\Python38\\lib', 'C:\\Users\\asus\\AppData\\Local\\Programs\\Python\\Python38', 'C:\\Users\\asus\\Music_Classification']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.platform&lt;/code&gt; can be used to identify the running platform (operating system).
&lt;/li&gt;
&lt;/ul&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="nn"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;win32
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.executable&lt;/code&gt; tells where the Python interpreter is present.
&lt;/li&gt;
&lt;/ul&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="nn"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;executable&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\asus\Music_Classification\Scripts\python.exe
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.modules&lt;/code&gt; returns a dictionary containing names of all modules in the current environemnt.
&lt;/li&gt;
&lt;/ul&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="nn"&gt;sys&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s"&gt;'sys'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'sys'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'builtins'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'builtins'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'_frozen_importlib'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'importlib._bootstrap'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&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="s"&gt;'_imp'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'_imp'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'_warnings'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'_warnings'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'_frozen_importlib_external'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'importlib._bootstrap_external'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&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="s"&gt;'_io'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'io'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'marshal'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'marshal'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'nt'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'nt'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'_thread'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'_thread'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'_weakref'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'_weakref'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'winreg'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'winreg'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'time'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'time'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'zipimport'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'zipimport'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&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="s"&gt;'_codecs'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'_codecs'&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;built&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="ow"&gt;in&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="s"&gt;'codecs'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'codecs'&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s"&gt;'C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Users&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;asus&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;AppData&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Local&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Programs&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Python38&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;lib&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;codecs.py'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'encodings.aliases'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;module&lt;/span&gt; &lt;span class="s"&gt;'encodings.aliases'&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s"&gt;'C:&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Users&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;asus&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;AppData&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Local&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Programs&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;Python38&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;lib&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;encodings&lt;/span&gt;&lt;span class="se"&gt;\\&lt;/span&gt;&lt;span class="s"&gt;aliases.py'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sys.exit&lt;/code&gt; can be used to terminate a program at once.&lt;/li&gt;
&lt;li&gt;Apart from these CLI usages, sys can be used for I/O as well:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;stdin&lt;/strong&gt; (Get input from the command line)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;stdout&lt;/strong&gt; (Display output on the screen, the beloved print is just a wrapper around stdout object)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;stderr&lt;/strong&gt; (The source of all the error messages, each and 
every exception is handled and written to stderr) &lt;/li&gt;
&lt;/ul&gt;


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

&lt;h2&gt;
  
  
  Advanced Usecase
&lt;/h2&gt;

&lt;p&gt;These are some simple usage of &lt;code&gt;sys&lt;/code&gt; module. Let's take one advanced use case:&lt;/p&gt;

&lt;p&gt;I made a script to determine the traffic on all of my GitHub Repositories. I was having a look at the Pickled database and was unable to determine the corresponding Repo. I knew that my script took the name of GitHub Repo as an argument. By using &lt;code&gt;sys.argv&lt;/code&gt; in the driver code. I was able to determine the exact arguments provided to the script.&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;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;"__main__"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Arguments: "&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;argv&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="mi"&gt;2021-05-13&lt;/span&gt;&lt;span class="err"&gt;T&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;Z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"uniques"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"count"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="mi"&gt;2021-05-20&lt;/span&gt;&lt;span class="err"&gt;T&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;00&lt;/span&gt;&lt;span class="err"&gt;Z&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"uniques"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"count"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;elements&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;Arguments:&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;'github_traffic.py'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'view'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'-u'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'vybhav&lt;/span&gt;&lt;span class="mi"&gt;72954&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'-r'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;'My_Junk'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Granted, there are more straightforward ways to sort this problem, but using &lt;code&gt;sys.argv&lt;/code&gt; can be really helpful when writing scripts containing multiple classes and functions.&lt;/p&gt;

&lt;h2&gt;
  
  
  In Closing
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Sys&lt;/strong&gt; is another helpful module in Python Standard Lib, which has multiple basic to advanced use cases, with standard I/O being the most practical application, &lt;code&gt;sys&lt;/code&gt; can be used in other scenarios as well, which are discussed above.&lt;/p&gt;

&lt;p&gt;There is much more to &lt;code&gt;sys&lt;/code&gt; but was out of scope for this blog like managing hooks, recursion depth, traces, encoding, and profiles. There are other useful methods as well; for a detailed insight, have a look &lt;a href="https://docs.python.org/3/library/sys.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Beginners Guide to Auto Formatting</title>
      <dc:creator>vybhav72954</dc:creator>
      <pubDate>Sun, 28 Mar 2021 17:41:56 +0000</pubDate>
      <link>https://dev.to/vybhav/beginners-guide-to-auto-formatting-1hpp</link>
      <guid>https://dev.to/vybhav/beginners-guide-to-auto-formatting-1hpp</guid>
      <description>&lt;p&gt;Everybody loves Python! (mostly). But why? I asked many programmers across my network (Trust me, I did!). And the most pronounced response was its high readability, simple syntax, and similar Pythonic traits. Indeed, a high level of readability was on the top of the mind of &lt;strong&gt;Guido van Rossum&lt;/strong&gt; as he developed Python.&lt;/p&gt;

&lt;p&gt;Let’s take a small example. The staple of all programs, the infamous &lt;strong&gt;“Hello World!” program&lt;/strong&gt; in Java, looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nc"&gt;Hello&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;World&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; 
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While in Python, it looks like this:&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="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;‘&lt;/span&gt;&lt;span class="n"&gt;Hello&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;world&lt;/span&gt;&lt;span class="err"&gt;!’&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks simple right? Even better examples, like opening and appending files in Python, are comparatively more straightforward and less taxing than other languages.&lt;/p&gt;

&lt;p&gt;But before proceeding, let’s make a few things clear.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;There are languages with even simpler syntax and learning curves, Lisp and Smalltalk are great examples. Even Ruby on Rails can fit the constraints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even though it is simple, Python is not THE best programming language; there is NO best programming language. There are languages which you know, you love it and sharpen your skills using them, and there are languages which you don’t know and might learn someday own the line. (PHP is an exception, you never want to practice PHP).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are beginner-friendly languages, Python is one of them, but I don’t think it’s a good description.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Programming languages are situational, to say the least; it depends upon what you want to achieve, how you want to achieve, and when you want to achieve.&lt;/p&gt;




&lt;h2&gt;
  
  
  Python Styling Guidelines
&lt;/h2&gt;

&lt;p&gt;Now with that out of the way, let’s talk about why Python is so great 😛. So, like previously mentioned, is it the easy syntax? Higher flexibility? Or something else? Well actually the big picture is a little bit different. Python was developed with a high level of readability in mind, it’s the idea &lt;strong&gt;that code is read much more often than it is written&lt;/strong&gt;, and this is where everything glues together. &lt;/p&gt;

&lt;p&gt;Python is good because it is easier to &lt;strong&gt;read and comprehended&lt;/strong&gt;, sure it means that writing is more accessible. But writing is not the idea behind Python, it’s &lt;strong&gt;reading the code&lt;/strong&gt;. The easier syntax does make it easier to write the programs, but the true purpose they serve is to the readers and reviewers, other benefits are just cherry on top. For that very reason, Pythonistas follow a set of guidelines, a.k.a. “Pythonic” idioms. But why am I talking about this? It is evident that Python is flexible and easy to read/write; a lot of people are attracted to writing programs in Python, but what they forget is the styling part of Python, and hence the result is a poorly formatted code, which don’t get me wrong, still works fine but isn’t what Python is actually meant for. This tweet summarizes the Styling part really well.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F40ahsvkhevvpx87ugv3j.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F40ahsvkhevvpx87ugv3j.png" alt="tweet"&gt;&lt;/a&gt;&lt;/p&gt;







&lt;h3&gt;
  
  
  PEP-8
&lt;/h3&gt;

&lt;p&gt;In a nutshell, we have some not-so-strict styling guidelines for Python. Ummm NO. Actually, the procedures are very strict, adequately formatted, and universally accepted; just the problem is that beginners don’t abide by them, and with time it becomes habitual.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PEP-8 is the de facto code style guide for Python.&lt;/strong&gt; It should be strictly followed and mandatory in top projects such as “Flask”, “Tensorflow” etc.&lt;/p&gt;

&lt;p&gt;A well-documented version of the guidelines can be found &lt;a href="https://pep8.org/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. The &lt;a href="https://docs.python-guide.org/writing/style/" rel="noopener noreferrer"&gt;Hitchhiker’s Guide to Python&lt;/a&gt; is my go-to version of guidelines for properly formatted code.&lt;/p&gt;

&lt;p&gt;If you are a beginner and want a simpler take on PEP-8 guidelines, I have prepared my &lt;a href="https://github.com/HarshCasper/Rotten-Scripts/blob/master/Python/CONTRIBUTION-GUIDELINE.md" rel="noopener noreferrer"&gt;own version&lt;/a&gt; of Python guidelines used in an open-source project, &lt;a href="https://github.com/HarshCasper/Rotten-Scripts" rel="noopener noreferrer"&gt;Rotten-Scripts&lt;/a&gt;. This is way more beginner-friendly but also aligns with the mandatory guidelines of PEP-8.&lt;/p&gt;




&lt;h2&gt;
  
  
  Auto Formatting
&lt;/h2&gt;

&lt;p&gt;Now let’s address the elephant in the room; Have you just started coding in Python, and these guidelines seem way too much? Are you a seasoned pro, but PEP-8 guidelines still overwhelm you at times? There is a simple solution for all this, &lt;strong&gt;Auto Formatting&lt;/strong&gt;. Before getting into Auto Formatting, &lt;em&gt;it should be clear that the tools mentioned below can just act as an aid,&lt;/em&gt; and one should try to learn the guidelines, and one should be able to write good quality code without using any tool.&lt;/p&gt;

&lt;p&gt;Several auto-formatting tools can reformat your code to comply with PEP-8.&lt;br&gt;
We will discuss 3 of my favorites.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/autopep8/" rel="noopener noreferrer"&gt;autopep8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/google/yapf" rel="noopener noreferrer"&gt;yapf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/black/" rel="noopener noreferrer"&gt;black&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But before discussing auto-formatting, one question pops up in mind; What if my script is already looking good and everything is working correctly? For example, take this python script, &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhyz9yv93e397azytewcp.PNG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhyz9yv93e397azytewcp.PNG" alt="Test Script"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It looks horrible but is working correctly, now I know that this is a rather extreme example, but it serves the purpose here. Before anything, we need to determine what are the discrepancies in our code. For this, we will use &lt;code&gt;pycodestyle&lt;/code&gt;, previously known as &lt;code&gt;pep8&lt;/code&gt;.&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;pycodestyle
pycodestyle test.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&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;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E401&lt;/span&gt; &lt;span class="n"&gt;multiple&lt;/span&gt; &lt;span class="n"&gt;imports&lt;/span&gt; &lt;span class="n"&gt;on&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E703&lt;/span&gt; &lt;span class="n"&gt;statement&lt;/span&gt; &lt;span class="n"&gt;ends&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;semicolon&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E302&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="n"&gt;blank&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;found&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E265&lt;/span&gt; &lt;span class="n"&gt;block&lt;/span&gt; &lt;span class="n"&gt;comment&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; &lt;span class="k"&gt;with&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="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E501&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="n"&gt;too&lt;/span&gt; &lt;span class="nf"&gt;long &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;135&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;79&lt;/span&gt; &lt;span class="n"&gt;characters&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E225&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="n"&gt;around&lt;/span&gt; &lt;span class="n"&gt;operator&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E201&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="n"&gt;after&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="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E231&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="n"&gt;after&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="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E231&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="n"&gt;after&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="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;31&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E202&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="n"&gt;before&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="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E703&lt;/span&gt; &lt;span class="n"&gt;statement&lt;/span&gt; &lt;span class="n"&gt;ends&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;semicolon&lt;/span&gt;
&lt;span class="n"&gt;test&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;18&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;E225&lt;/span&gt; &lt;span class="n"&gt;missing&lt;/span&gt; &lt;span class="n"&gt;whitespace&lt;/span&gt; &lt;span class="n"&gt;around&lt;/span&gt; &lt;span class="n"&gt;operator&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="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As expected there are a lot of problems here, this code is nothing short of a nightmare for a debugger and/or reviewer. Now we can start playing around using the autoformatting tools mentioned above. I won’t be discussing the detailed workings of these tools, as they have proper documentation, multiple options, and configurations for helping you out. Instead, we will be focusing on some hands-on implementation of the formating tools to provide a good starting ground.&lt;/p&gt;

&lt;p&gt;So, let’s start by downloading the required packages. I personally prefer to make separate virtual environments for these tools, validate a copy of my scripts in that virtual environment, and simply do the changes in the original scripts. You can do the same by &lt;a href="https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/" rel="noopener noreferrer"&gt;setting up a virtual environment&lt;/a&gt; and run the following commands. &lt;strong&gt;I am planning to make a cheat sheet for this soon as well, stay tuned.&lt;/strong&gt;&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;yapf black autopep8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After downloading all the required packages, let’s use all the formatting tools one by one and see how they can help us. All the tools follow similar steps and provide matching options but can still offer different results. Just ensure that you are in the directory in which your scripts are.&lt;/p&gt;




&lt;h4&gt;
  
  
  Autopep8
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Autopep8&lt;/strong&gt;, Just like its name, it automatically formats Python code to conform to the PEP-8 style guide. A simple hands-on approach autopep8 is widely regarded for its flexibility and customization. To correct your file, use 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;autopep8 &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; test.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-i&lt;/code&gt; or &lt;code&gt;--in-place&lt;/code&gt; flag make changes to files in place, and &lt;code&gt;-v&lt;/code&gt; or &lt;code&gt;--verbose&lt;/code&gt; is for verbose messages.&lt;/p&gt;

&lt;p&gt;Output:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fikcczqxzcyi4mtnrgom8.PNG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fikcczqxzcyi4mtnrgom8.PNG" alt="Test Script after autopep8"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look at that, way better! But wait, there is more. The good thing about &lt;code&gt;autopep8&lt;/code&gt; is, it allows aggressive changes as well. By using &lt;code&gt;-a&lt;/code&gt; or &lt;code&gt;--aggressive&lt;/code&gt; flag, &lt;code&gt;autopep8&lt;/code&gt; aggressively formats the code, enabling non-whitespace changes. Let's see this in action, shall we?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;autopep8 &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; test.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1o79djf7lvq2rbky1c7g.PNG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1o79djf7lvq2rbky1c7g.PNG" alt="Test Script after autopep8 aggressive"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clearly so much has changed, this shows how flexible &lt;code&gt;auotpep8&lt;/code&gt; actually is, but there is even more.&lt;/p&gt;

&lt;p&gt;By stacking multiple &lt;code&gt;-a&lt;/code&gt;,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;autopep8 &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt; test.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;even more aggressive changes can be forced. After using the aggressive flag multiple times, this is what the file looks like.&lt;/p&gt;

&lt;p&gt;Output:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokf5k0ohrbj6gwvzs1jn.PNG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fokf5k0ohrbj6gwvzs1jn.PNG" alt="Test Script after autopep8 aggressive 3 layers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;3 level of aggressive changes in my opinion is a bit of overkill and solves most of the purposes.&lt;/p&gt;




&lt;h4&gt;
  
  
  YAPF
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;YAPF&lt;/strong&gt; is a project by Google is a rather advanced auto-formatting tool and can even beautify code that follows PEP-8 guidelines to make it look even better. The approach is similar to &lt;code&gt;clang&lt;/code&gt; and &lt;code&gt;gofmt&lt;/code&gt;, in order to auto-format a file, use 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;yapf &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-vv&lt;/span&gt; test.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;-i&lt;/code&gt; or &lt;code&gt;--in-place&lt;/code&gt; flag make changes to files in place, and &lt;code&gt;-vv&lt;/code&gt; or &lt;code&gt;--verbose&lt;/code&gt; is for verbose messages.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh14psmigy3j4fdiebis.PNG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzh14psmigy3j4fdiebis.PNG" alt="Test Script after yapf"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yapf&lt;/code&gt; allows you to format the code according to Google and Facebook guidelines as well; by using &lt;code&gt;style google&lt;/code&gt; or &lt;code&gt;style facebook&lt;/code&gt; scripts can be reformatted according to the prescribed styling guidelines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yapf &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nt"&gt;-vv&lt;/span&gt; test.py style google
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h4&gt;
  
  
  Black
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Black&lt;/strong&gt; is the most-loved and/or most-hated formatter (depends on how you look at it), a truly uncompromising formatter, refactoring the code to its minute details, black results in a faster, more optimized code. Its uncompromising nature can result in scripts utterly different from the original ones and is many a time considered an overfill. In order to use black, use the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;black test.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsflnyh6t7pu4rrf80clw.PNG" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fsflnyh6t7pu4rrf80clw.PNG" alt="Test Script after black"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice the shift from single to double quote, extra blank lines, etc. Black incorporates multiple changes that can completely change the way a script looks like.&lt;/p&gt;




&lt;p&gt;Coming back to my early statement, &lt;em&gt;&lt;code&gt;Black&lt;/code&gt; is the most-loved and/or most-hated formatter&lt;/em&gt;, &lt;strong&gt;how?&lt;/strong&gt; &lt;code&gt;Black&lt;/code&gt; provides nearly &lt;strong&gt;No&lt;/strong&gt;, and by that, I mean no customization; it is truly uncompromising. There are definitely things that can be changed, but the fact that Black is a simple nonconfigurable tool still holds true. A common argument is that the "best tools do not need any configurations"; this might hold true for &lt;code&gt;gofmt&lt;/code&gt; (a similar auto-formatting tool for Go) but Python is not Go. A lot of people still love using &lt;code&gt;Black&lt;/code&gt;. &lt;strong&gt;“Black is opinionated, so you don’t need to be.”&lt;/strong&gt; sum everything up pretty well.&lt;/p&gt;

&lt;p&gt;Other tools like &lt;code&gt;autopep8&lt;/code&gt; and &lt;code&gt;yapf&lt;/code&gt; provide much more configurations and customizations, but that part is out of this article’s scope.&lt;/p&gt;







&lt;h3&gt;
  
  
  Why no Auto Formatter?
&lt;/h3&gt;

&lt;p&gt;There are reasons why you should not use Auto-Formatter, like the unnecessary clutter that Black introduces in the output of &lt;code&gt;git blame&lt;/code&gt;, but since the newer versions of git, these problems have been solved, and tools support ignoring revisions, so its no longer an issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  My Final Take
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Black&lt;/code&gt;, &lt;code&gt;yapf&lt;/code&gt;, and &lt;code&gt;autopep8&lt;/code&gt; are some great tools, but personally, &lt;code&gt;autopep8&lt;/code&gt; is my go-to auto formatter with a &lt;code&gt;flake8 linter&lt;/code&gt; (What is a linter? Wait for my next blog, maybe :P) and &lt;code&gt;Travis&lt;/code&gt; for test cases and continuous integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bottom-line:
&lt;/h2&gt;

&lt;p&gt;Auto format tools like &lt;code&gt;yapf&lt;/code&gt;, &lt;code&gt;autopep8&lt;/code&gt; and &lt;code&gt;black&lt;/code&gt; are just &lt;strong&gt;options, not solutions&lt;/strong&gt;. Ultimately you should strive to learn the guidelines yourself as they are the heart and soul of Python. In case you are contributing to open-source projects, tools like these help a lot. Every maintainer loves good clean code. Always remember, &lt;em&gt;it is not enough for code to work if you want, So if you want to go fast, if you want to get done quickly, if you want your code to be easy to write, make it easy to read.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Like I said earlier, &lt;strong&gt;I am planning to make a cheat sheet for this soon as well, stay tuned.&lt;/strong&gt;&lt;/p&gt;




&lt;p&gt;Liked what you read? I have restarted blogging after a long time; I talk about multiple stuff (Football, Anime, IoT, Music, Human Emotions, to name a few). You can follow me on my socials if you want.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Let connect; I love to get in touch with people who have a similar mindset, my &lt;a href="https://www.linkedin.com/in/vybhav-chaturvedi-0ba82614a/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;exclusive Tech Posts&lt;/strong&gt;, check my &lt;a href="https://dev.to/vybhav"&gt;Dev Profile&lt;/a&gt;. &lt;/li&gt;
&lt;li&gt;Go through my &lt;a href="https://github.com/vybhav72954" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, you might find something interesting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Vybhav Chaturvedi&lt;/em&gt;, Over and Out.&lt;/p&gt;







</description>
      <category>python</category>
      <category>tooling</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>First steps in GirlScript Summer of Code'21</title>
      <dc:creator>vybhav72954</dc:creator>
      <pubDate>Fri, 12 Mar 2021 09:50:12 +0000</pubDate>
      <link>https://dev.to/vybhav/first-steps-in-girlscript-summer-of-code-21-2353</link>
      <guid>https://dev.to/vybhav/first-steps-in-girlscript-summer-of-code-21-2353</guid>
      <description>&lt;p&gt;&lt;strong&gt;2020&lt;/strong&gt; was crazy, from UFO videos to missing stars, a possible World War in the first week (Trolls) to a Worldwide pandemic, 2020 told everyone to hold its beer. And subsequently, we had the Worldwide Lockdown, no Colleges (Yippee), Work from Home (Sign me up for that), no Football (Well, that's bad), no Adventures, Trips, Movies, get together (Why 2020, why?) but still I enjoyed it a lot, cause during the early Lockdown I decided to get back into Open Source after a break of nearly two years. It was my first ever 2-month long Hackathon, and I was going crazy. I enjoyed working on a fantastic project under a smart and experienced mentor, the Semester Long Projects &lt;a href="https://slop.dscdaiict.in/" rel="noopener noreferrer"&gt;SLoP 2020&lt;/a&gt;, organized by the Developers Club of Dhirubhai Ambani Institute of Information and Communication Technology, was a memorable experience, with a nail-biting finish I was eventually able to secure the first position. It was a fantastic event, and more than winning, I was more excited to make connections that are still strong. I worked and got to know many people whose names still keep popping up here and there. After that one event, I never looked back, participated in various events, hackathons, and competitions, performing well in some, and even underperformed at times. Open Source made Lockdown a whole lot memorable for me.&lt;/p&gt;

&lt;p&gt;Recently &lt;a href="https://gssoc.girlscript.tech/index.html" rel="noopener noreferrer"&gt;GirlScript Summer of Code&lt;/a&gt; came along, a vastly popular event organized by a well-respected EdTech organization, The GirlScript foundation. It is a 3-month long event dedicated to Open Source and provides a well-rounded opportunity to beginners who are just taking their first step into Open Source along with the seasonal professionals who are looking to contribute to a well-structured project. Numerous internship opportunities, fantastic prizes, and acclamation are just the tip of the iceberg as GirlScript Summer of Code (usually called GSSoC) guarantees the participants with an expanded network and a rigorous 3-month program full of coding (wow), documentation (hell yeah) and debugging (oh no!). A big shoutout to &lt;a href="https://github.com/HarshCasper" rel="noopener noreferrer"&gt;Harsh Mishra&lt;/a&gt; for recommending GSSoC to me and helping me throughout the process as I applied for the Mentor role in GSSoC. After waiting for days full of anticipation, I finally received the e-mail; for the next three months, I was going to be a mentor in GSSoC'21.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr1v7iyspirmb0493p05p.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr1v7iyspirmb0493p05p.png" alt="GSSoC Badge"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;But this post is not about my role as a mentor, nor it's about GSSoC as a competition; there are more suitable blogs than this about the event and personals with a better story. This blog is meant for those who are taking their first step in Open Source via GSSoC; I will try my level best to guide you throughout the competition, help you open your first issue and your first Pull Request (I prefer to call it PR) and provide you some easy cheats which won't guarantee you a podium but will undoubtedly help you in enjoying the event to its fullest. The event is yet to pick up its pace (the coding period started on the 8th of March), but with approximately 6000 participants, the hype is definitely real. But don't get me wrong, GSSoC is solely meant to promote Open Source, and OSS means that it is open for everyone, so it doesn't matter if you are a GSSoC participant or not; it doesn't matter whether you have mastered your Tech Stack or not, all that matters is that you have decided to step into Open Source and trust me you are in for a treat. With these words, buckle up everybody, and let's talk about contributing to GSSoC or Open Source in general.&lt;/p&gt;

&lt;h1&gt;
  
  
  First step in GSSoC'21?
&lt;/h1&gt;

&lt;p&gt;Well, first of all, you need to register in GSSoC, ensure that you perform all the formalities the organizers ask you to fulfill, join the official communication channels, and you are good to go!&lt;/p&gt;

&lt;h2&gt;
  
  
  How GSSoC works?
&lt;/h2&gt;

&lt;p&gt;How does GSSoC work, you ask? It's quite simple. In layman's terms, multiple people apply to register their project under the banner of GSSoC, the owners (called Project Admins) of the projects that are accepted than are assigned a bunch of mentors (usually 2-3) who are tasked to help the Admins throughout the three months. Participants can contribute to these projects and earn points, and now you know where I am going with this, prizes are distributed based on points earned yadda yadda yadda.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to choose a project?
&lt;/h2&gt;

&lt;p&gt;Before choosing a project, we need to ask ourselves a few questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What languages, tech stack, framework. Am I proficient in? None is also acceptable, to be honest.&lt;/li&gt;
&lt;li&gt;What languages, tech stack, framework. I want to learn/master or at least get the hang of it after these three months?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The best part about GSSoC is the number of projects that one can choose from; with nearly 100 projects using various tech stacks to select from, GSSoC has something for everyone. Fond of Web development, multiple projects are using MERN, MEAN, MEVN, ROR stack. Love Machine learning and Deep Learning, there are projects which specifically focus on classification and prediction. Love Python? Do take a look at multiple Flask and Django projects. Willing to master DS and Algo, GSSoC has got you covered. From beginners to advanced, you will for sure find something. You don't the coding and debugging part? How about Documentation? Nearly every project needs that.&lt;/p&gt;

&lt;p&gt;So now we know our preferred tech stacks, let's look for projects on the &lt;a href="https://gssoc.girlscript.tech/projects.html" rel="noopener noreferrer"&gt;GSSoC official website&lt;/a&gt;. As for now, you are allowed to contribute to any project, make a list of all the projects you find interesting, star them (to show your appreciation), and then we can start hunting for issues to solve.&lt;/p&gt;

&lt;p&gt;Every Project on GitHub has an Issues section; go to the issues section and go through all the issues which have &lt;code&gt;GSSOC21&lt;/code&gt; label and are &lt;strong&gt;not assigned&lt;/strong&gt; to anybody (it's crucial), while most of the projects prefer to have one person working or assigned to an issue, some projects might not follow this workflow; hence it is always recommended to ask the mentors and admins of the project before working on an issue. After you have found the issue you think you can solve, leave a comment like _ "Hey there, I think I can solve this issue, I will use this scheme, and will probably take this much time, "_ and then wait till the issue is assigned to you, this is important as this is not a race instead of a collaborative event. But wait, I can't find any issue to work on; what should I do now? No problem at all, go through the codebase once, try to find a bug (something that doesn't look right) which can be anything from a Typo to a Glitch fest, or try finding a missing feature (Something that is missing), open an issue for the same, and you are good to go, but remember to wait for the Admins and mentors to go through your issue once.&lt;/p&gt;

&lt;p&gt;So finally, the issue has been assigned; the mentor has labeled it as GSSOC21 or similar and also assigned the difficulty level; ask the mentor to put them if the labels are missing. Now what?&lt;br&gt;
Here is where the Best Part start. It's time to get your hands dirty. Now in the subsequent steps, I will tell you how you should make your PR.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Dirty Work
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Forking Projects
&lt;/h3&gt;

&lt;p&gt;Let's start by Forking the Project.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil2twqyv8x4ofo0nzjoa.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil2twqyv8x4ofo0nzjoa.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This will create a Local Copy of the Repository on your GitHub Profile. &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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7lt38ihg9dggwo9nheb.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7lt38ihg9dggwo9nheb.png" alt="2nd done"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Cloning
&lt;/h3&gt;

&lt;p&gt;Now we can start with cloning the Repo in our local system. Moreover, it is recommended to keep the reference to the Original Project in &lt;code&gt;upstream.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/&amp;lt;your-username&amp;gt;/&amp;lt;repo-name&amp;gt;  
&lt;span class="nb"&gt;cd&lt;/span&gt; &amp;lt;repo-name&amp;gt;  
git remote add upstream https://github.com/&amp;lt;upstream-owner&amp;gt;/&amp;lt;repo-name&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Updating Copy
&lt;/h4&gt;

&lt;p&gt;You might need to update our copy (if you forked earlier and the project had gone through changes); for that, we can use two methods.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Merge (Not preferred)&lt;/li&gt;
&lt;li&gt;Rebase (Preferable)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote update
git checkout &amp;lt;branch-name&amp;gt;
git rebase upstream/&amp;lt;branch-name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Branching
&lt;/h3&gt;

&lt;p&gt;Our fork and the local copy are up to date; now it's time to work on the issue assigned to you.&lt;br&gt;
There is a general non-breaking rule, you should never make a PR from the master, although this won't break anything, but it is a general practice and is very helpful if you mess up the commit history, so first of all, let's &lt;code&gt;checkout&lt;/code&gt; to a new branch.&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="c"&gt;# It will create a new branch with the name Branch_Name and switch to that branch &lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; branch_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice that you checkout to the new branch from the initial branch only.&lt;/p&gt;

&lt;p&gt;So, suppose if you were in branch master and checked out to foo and then again used the command to checkout to bar. The branch is made from foo, not master. (Confusing? Never mind, as a general rule of thumb, always ensure to checkout to master using command whenever you are going to work on a new issue).&lt;/p&gt;

&lt;h3&gt;
  
  
  Working Remotely
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Now get your hands dirty, code, edit and debug.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All set? You proofread, right? &lt;em&gt;Do it once more.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now, let's tell git to track the new files.&lt;br&gt;
Let's start with a git status to check what has changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Commit
&lt;/h3&gt;

&lt;p&gt;After you've made changes or made your contribution to the project, add changes to the branch you've just created by:&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="c"&gt;# To add only a few files to Branch_Name&lt;/span&gt;
git add &amp;lt;some files&amp;gt;

&lt;span class="c"&gt;# To add all new files to branch Branch_Name  &lt;/span&gt;
git add &lt;span class="nb"&gt;.&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To commit, give a descriptive message for the convenience of the reviewer by:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"message"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Always write a sensible commit message; it's a good practice and more comfortable for a 3rd person to comprehend.&lt;/p&gt;

&lt;h3&gt;
  
  
  Push the Commits and Pull Request
&lt;/h3&gt;

&lt;p&gt;You have completed the most challenging part; now, all you need to do is, Push the commits, make a PR sit back, take a deep breath and wait for your mentors to review the PR.&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="c"&gt;# To push your work to your remote repository&lt;/span&gt;
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin Branch_Name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After pushing the commits, this message will pop up:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxsidiav1kiq23edvsz6g.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxsidiav1kiq23edvsz6g.png" alt="PR"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, time to make a Pull Request; the process is simple, give a proper title, and explain the changes you have made. This is what your PR should look like.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyakhytbsj8fyy23q8j3n.png" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyakhytbsj8fyy23q8j3n.png" alt="3rdDone"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Remember &lt;code&gt;Fixes #issue_num&lt;/code&gt; is very important. &lt;/p&gt;

&lt;p&gt;But while you wait, why not start working on a new issue. Follow the same steps for any project, &lt;strong&gt;Fork Clone Branch Add Commit Push&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;[&lt;em&gt;Note: If you are going to work on a different issue in the same project, do checkout to master before making a new branch&lt;/em&gt;].&lt;/p&gt;

&lt;p&gt;But what if your mentor is not satisfied? No pressure you have got this, usually, they also tell you some vital information, like what is lacking, what to change.&lt;/p&gt;

&lt;p&gt;Checkout to the branch, make those changes, &lt;strong&gt;Add, Commit, Push&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Viola, you updated your PR with another commit. &lt;em&gt;Way to go&lt;/em&gt;.&lt;/p&gt;




&lt;p&gt;This is the general workflow of any GitHub contribution and applies to every project, so while you are at it, look for other organizations and repositories to contribute to, search for &lt;code&gt;good-first-issues&lt;/code&gt; they are usually easy and one excellent place to start.&lt;/p&gt;

&lt;p&gt;Soon I will make a blog about all programs like GSSoC, which will help you to take part in programs like GSSoC; who knows, you might grab a good result in that event, you can follow me so that you don't miss it.&lt;/p&gt;




&lt;p&gt;But before we conclude, we need to discuss something essential. Some essential rules of Open Source which you must abide by because, after all, we are in the same boat and must help each other. Kindly keep these things in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Be Nice, Be Respectful&lt;/strong&gt; (BNBR)&lt;/li&gt;
&lt;li&gt;Check if the issue you created &lt;strong&gt;exists or not&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Make &lt;strong&gt;good commit messages&lt;/strong&gt; and document your PR well.&lt;/li&gt;
&lt;li&gt;Always &lt;strong&gt;add Comments&lt;/strong&gt; in your code and explain it at points.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Input&lt;/strong&gt; is always preferred over static Driver Code.&lt;/li&gt;
&lt;li&gt;Always create a &lt;strong&gt;Pull Request from a Branch&lt;/strong&gt;; Never from the master.&lt;/li&gt;
&lt;li&gt;Follow proper Code conventions. Using &lt;code&gt;i',&lt;/code&gt;j` in Loops shows a poor understanding of Code Quality. Use appropriate Variable, Function Names.&lt;/li&gt;
&lt;li&gt;Code would be reviewed by Mentors before they are merged. &lt;strong&gt;Every good PR requires Reviews&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  That's all, folks.
&lt;/h6&gt;




&lt;p&gt;Thank you so much for sticking with me till here. All the images used are of the Project Rotten-Scripts. I am one of the mentors of the project and would love to have you over there as well. Feel free to hang around, open an issue, maybe. There are many such awesome projects in GSSoC. Like I have said already, start contributing ASAP.&lt;/p&gt;

&lt;p&gt;Liked what you read? I have restarted blogging after a long time; I talk about multiple stuff (Football, Anime, IoT, Music, Human Emotions, to name a few). You can follow me on my socials if you want.&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Let connect; I love to get in touch with people who have a similar mindset, my &lt;a href="https://www.linkedin.com/in/vybhav-chaturvedi-0ba82614a/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For &lt;strong&gt;exclusive Tech Posts&lt;/strong&gt;, check my &lt;a href="https://dev.to/vybhav"&gt;Dev Profile&lt;/a&gt;. &lt;/li&gt;
&lt;li&gt;Go through my &lt;a href="https://github.com/vybhav72954" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;, you might find something interesting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All the images have been taken from &lt;a href="https://github.com/HarshCasper/Rotten-Scripts" rel="noopener noreferrer"&gt;Rotten-Scripts&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Vybhav Chaturvedi&lt;/em&gt;, Over and Out.&lt;/p&gt;







</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
