<?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: Sahdev Garg</title>
    <description>The latest articles on DEV Community by Sahdev Garg (@djangochain).</description>
    <link>https://dev.to/djangochain</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%2F781893%2F6ee2f431-7b57-4a96-b79c-7fa294df6071.png</url>
      <title>DEV Community: Sahdev Garg</title>
      <link>https://dev.to/djangochain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/djangochain"/>
    <language>en</language>
    <item>
      <title>Python Style Guide PEP 8</title>
      <dc:creator>Sahdev Garg</dc:creator>
      <pubDate>Wed, 29 Dec 2021 06:29:07 +0000</pubDate>
      <link>https://dev.to/djangochain/demystifying-pythons-style-guide-pep-8-j7k</link>
      <guid>https://dev.to/djangochain/demystifying-pythons-style-guide-pep-8-j7k</guid>
      <description>&lt;h2&gt;
  
  
  What is PEP 8 ?
&lt;/h2&gt;

&lt;p&gt;Before going into details of PEP 8 the first thing that we need to understand that what exactly is PEP and what is 8 signifies in PEP 8.&lt;br&gt;
PEP contains the index of all Python Enhancement Proposals, known as PEPs. This is an aggregate of documents which explains about information, new features, process and environment settings for python community.&lt;br&gt;
PEP numbers are assigned by the PEP editors, and once assigned are never changed. It signifies the document number.&lt;br&gt;
PEP 8 means Python Enhancement Proposal document number 8 which details about Style Guide for Python Code. This style guide evolves over time as additional conventions are identified and past conventions are rendered obsolete by changes in the language itself.&lt;br&gt;
Although there is no restriction of using all the PEP 8 rule these are good to have as it helps in making code consistency and improve code readability.&lt;/p&gt;

&lt;p&gt;You can install, upgrade, uninstall pycodestyle.py (formerly called pep8)with these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install pycodestyle
$ pip install --upgrade pycodestyle
$ pip uninstall pycodestyle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pycodestyle(formerly called pep8) Usage
&lt;/h2&gt;

&lt;p&gt;For demo purpose lets created a test python file with a function to find the max between two numbers find_max.py having content as -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def find_max_number(a:int,b:int)-&amp;gt;int:
    return a if a&amp;gt;b else b
if __name__ == "__main__":
    find_max_number(10,15)
Executing pycodestyle for this file
pycodestyle find_max.py
find_max.py:3:22: E231 missing whitespace after ':'
find_max.py:3:26: E231 missing whitespace after ','
find_max.py:3:28: E231 missing whitespace after ':'
find_max.py:3:33: E225 missing whitespace around operator
find_max.py:4:18: E225 missing whitespace around operator
find_max.py:6:1: E305 expected 2 blank lines after class or function definition, found 1
find_max.py:7:23: E231 missing whitespace after ','
find_max.py:7:27: W292 no newline at end of file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case we have 8 violations.&lt;br&gt;
As you see above, it outputs the file name which has violations, location, error code and that content.&lt;/p&gt;

&lt;p&gt;In order to get output summary of PEP 8 violations we need run the following command &lt;code&gt;pycodestyle --statistics --qq &amp;lt;file_name&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pycodestyle  --statistics -qq find_max.py
2       E225 missing whitespace around operator
4       E231 missing whitespace after ':'
1       E305 expected 2 blank lines after class or function definition, found 1
1       W292 no newline at end of file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to have more details on the voilation we need to use show-source option as &lt;code&gt;pycodestyle --show-source &amp;lt;file_name&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pycodestyle  --show-source  find_max.py 
find_max.py:3:22: E231 missing whitespace after ':'
def find_max_number(a:int,b:int)-&amp;gt;int:
                     ^
find_max.py:3:26: E231 missing whitespace after ','
def find_max_number(a:int,b:int)-&amp;gt;int:
                         ^
find_max.py:3:28: E231 missing whitespace after ':'
def find_max_number(a:int,b:int)-&amp;gt;int:
                           ^
find_max.py:3:33: E225 missing whitespace around operator
def find_max_number(a:int,b:int)-&amp;gt;int:
                                ^
find_max.py:4:18: E225 missing whitespace around operator
    return a if a&amp;gt;b else b
                 ^
find_max.py:6:1: E305 expected 2 blank lines after class or function definition, found 1
if __name__ == "__main__":
^
find_max.py:7:23: E231 missing whitespace after ','
    find_max_number(10,15)
                      ^
find_max.py:7:27: W292 no newline at end of file
    find_max_number(10,15)
                        ^
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Moreover you can see the description of how to fix. This is &lt;code&gt;--show-pep8&lt;/code&gt; option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pycodestyle --show-pep8 find_max.py
find_max.py:3:22: E231 missing whitespace after ':'
    Each comma, semicolon or colon should be followed by whitespace.
Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
find_max.py:3:26: E231 missing whitespace after ','
    Each comma, semicolon or colon should be followed by whitespace.
Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
find_max.py:3:28: E231 missing whitespace after ':'
    Each comma, semicolon or colon should be followed by whitespace.
Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
find_max.py:3:33: E225 missing whitespace around operator
    Surround operators with a single space on either side.
- Always surround these binary operators with a single space on
      either side: assignment (=), augmented assignment (+=, -= etc.),
      comparisons (==, &amp;lt;, &amp;gt;, !=, &amp;lt;=, &amp;gt;=, in, not in, is, is not),
      Booleans (and, or, not).
- If operators with different priorities are used, consider adding
      whitespace around the operators with the lowest priorities.
Okay: i = i + 1
    Okay: submitted += 1
    Okay: x = x * 2 - 1
    Okay: hypot2 = x * x + y * y
    Okay: c = (a + b) * (a - b)
    Okay: foo(bar, key='word', *args, **kwargs)
    Okay: alpha[:-i]
E225: i=i+1
    E225: submitted +=1
    E225: x = x /2 - 1
    E225: z = x **y
    E225: z = 1and 1
    E226: c = (a+b) * (a-b)
    E226: hypot2 = x*x + y*y
    E227: c = a|b
    E228: msg = fmt%(errno, errmsg)
find_max.py:4:18: E225 missing whitespace around operator
    Surround operators with a single space on either side.
- Always surround these binary operators with a single space on
      either side: assignment (=), augmented assignment (+=, -= etc.),
      comparisons (==, &amp;lt;, &amp;gt;, !=, &amp;lt;=, &amp;gt;=, in, not in, is, is not),
      Booleans (and, or, not).
- If operators with different priorities are used, consider adding
      whitespace around the operators with the lowest priorities.
Okay: i = i + 1
    Okay: submitted += 1
    Okay: x = x * 2 - 1
    Okay: hypot2 = x * x + y * y
    Okay: c = (a + b) * (a - b)
    Okay: foo(bar, key='word', *args, **kwargs)
    Okay: alpha[:-i]
E225: i=i+1
    E225: submitted +=1
    E225: x = x /2 - 1
    E225: z = x **y
    E225: z = 1and 1
    E226: c = (a+b) * (a-b)
    E226: hypot2 = x*x + y*y
    E227: c = a|b
    E228: msg = fmt%(errno, errmsg)
find_max.py:6:1: E305 expected 2 blank lines after class or function definition, found 1
    Separate top-level function and class definitions with two blank
    lines.
Method definitions inside a class are separated by a single blank
    line.
Extra blank lines may be used (sparingly) to separate groups of
    related functions.  Blank lines may be omitted between a bunch of
    related one-liners (e.g. a set of dummy implementations).
Use blank lines in functions, sparingly, to indicate logical
    sections.
Okay: def a():\n    pass\n\n\ndef b():\n    pass
    Okay: def a():\n    pass\n\n\nasync def b():\n    pass
    Okay: def a():\n    pass\n\n\n# Foo\n# Bar\n\ndef b():\n    pass
    Okay: default = 1\nfoo = 1
    Okay: classify = 1\nfoo = 1
E301: class Foo:\n    b = 0\n    def bar():\n        pass
    E302: def a():\n    pass\n\ndef b(n):\n    pass
    E302: def a():\n    pass\n\nasync def b(n):\n    pass
    E303: def a():\n    pass\n\n\n\ndef b(n):\n    pass
    E303: def a():\n\n\n\n    pass
    E304: @decorator\n\ndef a():\n    pass
    E305: def a():\n    pass\na()
    E306: def a():\n    def b():\n        pass\n    def c():\n        pass
find_max.py:7:23: E231 missing whitespace after ','
    Each comma, semicolon or colon should be followed by whitespace.
Okay: [a, b]
    Okay: (3,)
    Okay: a[1:4]
    Okay: a[:4]
    Okay: a[1:]
    Okay: a[1:4:2]
    E231: ['a','b']
    E231: foo(bar,baz)
    E231: [{'a':'b'}]
find_max.py:7:27: W292 no newline at end of file
    Trailing blank lines are superfluous.
Okay: spam(1)
    W391: spam(1)\n
However the last line should end with a new line (warning W292).
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we want to exclude specific errors and warning while running pycodestyle we can use the option &lt;code&gt;-ignore&lt;/code&gt; and provide the comma separated values of the error codes need to be excluded.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pycodestyle - ignore=E231,E225 find_max.py
find_max.py:6:1: E305 expected 2 blank lines after class or function definition, found 1
find_max.py:7:27: W292 no newline at end of file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we have put E231,E225 in the ignore list the PEP 8 violation count reduced to 2 from 8 which is without ignoring these errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  PEP 8 Error codes
&lt;/h2&gt;

&lt;p&gt;Code can either denote an error or warning in case of error codes the code start with E followed by a 3 digit number for e.g E101 and for warning code it start with E followed by a 3 digit number for e.g W191.&lt;/p&gt;

&lt;p&gt;Below is the classification of error code based on series number.&lt;br&gt;
100 series … (E1 and W1) related to indentation.&lt;br&gt;
200 series … (E2 and W2) related to whitespace.&lt;br&gt;
300 series … (E3 and W3) related to blank lines.&lt;br&gt;
400 series … (E4 and W4) related to imports.&lt;br&gt;
500 series … (E5 and W5) related to line length.&lt;br&gt;
600 series … (E6 and W6) related to deprecation.&lt;br&gt;
700 series … (E7) related to statements.&lt;br&gt;
900 series … (E9) related to syntax errors.&lt;/p&gt;

&lt;p&gt;You can refer to official document for more detailing on error code &lt;a href="https://pep8.readthedocs.io/en/release-1.7.x/intro.html"&gt;link&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Customization of pep8
&lt;/h2&gt;

&lt;p&gt;We can customise the PEP 8 config to meet our requirement as in we might need to ignore certain errors and warning and also we want to alter the max-line-length etc.&lt;br&gt;
Default user configuration file is in '&lt;code&gt;~/.config/pycodestyle&lt;/code&gt;'.&lt;br&gt;
You can write the configuration file as below, this is same as option.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[pep8]
ignore = E231,E225
max-line-length = 160
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can specify the configuration file location by&lt;code&gt;--config=&amp;lt;configration_file_location&amp;gt;&lt;/code&gt; .&lt;br&gt;
By storing above configuration file in a certain location in respective projects, you can share it in the projects.&lt;br&gt;
At the project level, a setup.cfg file or a tox.ini file is read if present (.pep8 file is also supported, but it is deprecated). If none of these files have a [pep8] section, no project specific configuration is loaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  Commonly used PEP 8 guidelines
&lt;/h2&gt;

&lt;p&gt;The PEP 8 guidelines can classified in 7 different categories as&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code Lay-out&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use 4 spaces per indentation level.&lt;/li&gt;
&lt;li&gt;Use spaces not tabs python disallows mixing tabs and spaces for indentation.&lt;/li&gt;
&lt;li&gt;Limit all lines to a maximum of 79 characters.&lt;/li&gt;
&lt;li&gt;Should a line break before or after binary operator? In Python code, it is permissible to break before or after a binary operator, as long as the convention is consistent locally.&lt;/li&gt;
&lt;li&gt;Surround top-level function and class definitions with two blank lines.&lt;/li&gt;
&lt;li&gt;Code in the core Python distribution should always use UTF-8, and should not have an encoding declaration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Imports should be grouped in the following order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Standard library imports.&lt;/li&gt;
&lt;li&gt;Related third party imports.&lt;/li&gt;
&lt;li&gt;Local application/library specific imports.
Wildcard imports (from  import *) should be avoided.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Naming Conventions&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Naming conventions are the most important pillar in maintaining the code consistency and readability there is as such no rule book to define the naming conventions but PEP 8 has recommendation that is good to follow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Never use the characters 'l' , 'O' , or 'I' (uppercase letter eye) as single character variable names. In some fonts, these characters are indistinguishable from the numerals one and zero.&lt;/li&gt;
&lt;li&gt;Class names should normally use the Cap Words (Camel case) convention.&lt;/li&gt;
&lt;li&gt;Variables and function names should have all lowercase letters and underscores to separate words.&lt;/li&gt;
&lt;li&gt;Constant should have all uppercase letters with words separated by underscores&lt;/li&gt;
&lt;li&gt;Use the suffix "Error" on your exception names (if the exception actually is an error).&lt;/li&gt;
&lt;li&gt;Use self for the first argument to instance methods or class methods.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;String Quotes&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In Python, single-quoted strings and double-quoted strings are the same. PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability.&lt;/li&gt;
&lt;li&gt;Whitespace in Expression and Statement&lt;/li&gt;
&lt;li&gt;Avoid trailing whitespace anywhere. Because it's usually invisible, it can be confusing: e.g. a backslash followed by a space and a newline does not count as a line continuation marker.&lt;/li&gt;
&lt;li&gt;Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, &amp;lt;, &amp;gt;, !=, &amp;lt;&amp;gt;, &amp;lt;=, &amp;gt;=, in, not in, is, is not), Booleans (and, or, not).&lt;/li&gt;
&lt;li&gt;Use whitespace to communicate order of operations. x = 12*y + 22*z.&lt;/li&gt;
&lt;li&gt;Avoid excessive whitespace immediately inside of parenthesis, brackets, or braces.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;When to use trailing commas&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Trailing commas are usually optional, except they are mandatory when making a tuple of one element. For clarity, it is recommended to surround the latter in parentheses:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Correct:
FILES = ('setup.cfg',)
# Wrong:
FILES = 'setup.cfg',
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Programming Recommendations&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Comparisons to singletons like None should always be done with is or is not, never the equality operators.&lt;/li&gt;
&lt;li&gt;Use is notoperator rather than not ... is for e.g if foo is not None rather than if not foo is None:&lt;/li&gt;
&lt;li&gt;When implementing ordering operations with rich comparisons, it is best to implement all six operations (&lt;strong&gt;eq&lt;/strong&gt;, &lt;strong&gt;ne&lt;/strong&gt;, &lt;strong&gt;lt&lt;/strong&gt;, &lt;strong&gt;le&lt;/strong&gt;, &lt;strong&gt;gt&lt;/strong&gt;, &lt;strong&gt;ge&lt;/strong&gt;) rather than relying on other code to only exercise a particular comparison.&lt;/li&gt;
&lt;li&gt;When catching exceptions, mention specific exceptions whenever possible instead of using a bare except.&lt;/li&gt;
&lt;li&gt;Object type comparisons should always use isinstance() instead of comparing types directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Comments&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each line of a block comment starts with a # and a single space.&lt;br&gt;
Use inline comments only if it is unavoidable.&lt;br&gt;
Write docstrings for all public modules, functions, classes, and methods.&lt;br&gt;
Docstrings are not necessary for non-public methods, but you should have a comment that describes what the method does.&lt;/p&gt;

&lt;p&gt;For more detailing on the PEP 8 guidelines please check out the official documentation PEP 8 Guidelines&lt;/p&gt;

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

&lt;p&gt;Likewise pycodestyle there is flake8 which is also widely used for checking the code style PEP 8 guidelines in python code. It's always better to have these plugins in the ide and everytime you save or commit it will highlight the violations.&lt;br&gt;
Maintaining the code style guideline helps in better readability and code consistency. Although it's a good to have but always prefer to have coding guidelines while writing code.&lt;/p&gt;

</description>
      <category>python</category>
      <category>codequality</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Python code formatter Black</title>
      <dc:creator>Sahdev Garg</dc:creator>
      <pubDate>Tue, 28 Dec 2021 10:15:47 +0000</pubDate>
      <link>https://dev.to/djangochain/python-code-formatter-black-mk9</link>
      <guid>https://dev.to/djangochain/python-code-formatter-black-mk9</guid>
      <description>&lt;p&gt;Writing well-formatted code is very important, breaking the actual programs in easy to understand small programs as compared to having a more complex program helps in better understanding of code and helps in maintaining code quality. In python we have an automated package Black which helps in ensures code quality.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_owz6IQa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30l0btuhf4d8930qzgal.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_owz6IQa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30l0btuhf4d8930qzgal.jpeg" alt="Image black" width="780" height="520"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Black?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Black is known as the uncompromised Python code formatter. Unlike flake8 or pycodestyle rather then telling where the issue is and ask you to manually fix it Black not only report format errors but also fixes them. Black does not have a lot of options to tinker with and has a lot of opinion on how your code should look and feel. &lt;br&gt;
Black isn't for everyone and you may find something that is a dealbreaker for you personally, which is okay! The current Black code style is described here.&lt;br&gt;
Black can be easily integrated with many editors such as Vim, Emacs, VSCode, Atom or a version control system like GIT.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Installation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Black requires Python 3.6.2+ to run but has a capability to format Python 2 code too. &lt;br&gt;
For Python 3.6.2+ using pip.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install black&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Python 2 support needs the typed_ast dependency, which will be installed with pip install black[python2]. If you want to format Jupyter Notebooks, install pip install black[jupyter].&lt;br&gt;
If you can't wait for the latest hotness and want to install from GitHub, use:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pip install git+git://github.com/psf/black&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage of Black&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In simplest if we just want to format a file or a folder of files simple run the following command in terminal.&lt;br&gt;
&lt;code&gt;$ black {source_file_or_directory}...&lt;/code&gt;&lt;br&gt;
You can run Black as a package if running it as a script doesn't work:&lt;br&gt;
&lt;code&gt;$ python -m black {source_file_or_directory}...&lt;/code&gt;&lt;br&gt;
You can also pass code as a string using the -c / --code option.&lt;br&gt;
&lt;code&gt;$ black --code "print ( 'hello, black world' )"&lt;br&gt;
print("hello, black world")&lt;/code&gt;&lt;br&gt;
you can pass -v / --verbose that will cause Black to also emit messages about files that were not changed or were ignored due to exclusion patterns.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$  black -v spell_checker/ &lt;br&gt;
spell_checker/&lt;strong&gt;pycache&lt;/strong&gt; ignored: matches the .gitignore file content&lt;br&gt;
spell_checker/&lt;strong&gt;init&lt;/strong&gt;.py wasn't modified on disk since last run.&lt;br&gt;
spell_checker/spell_checker_util.py wasn't modified on disk since last run.&lt;br&gt;
spell_checker/spelling_checker.py wasn't modified on disk since last run.&lt;br&gt;
All done! ✨ 🍰 ✨&lt;br&gt;
3 files left unchanged.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Black Magic in action&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's create an unformatted file name "black_test.py" and we want to format it using black. Below is the code snippet from the file before formatting.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;def find_no_in_list(&lt;br&gt;
         s,&lt;br&gt;
            no&lt;br&gt;
         ):&lt;br&gt;
   s = list(s&lt;br&gt;
            )&lt;br&gt;
   for i in range(len(s) - 1):&lt;br&gt;
      if s[i] == no:&lt;br&gt;
         return i&lt;br&gt;
   else:&lt;br&gt;
      return -1&lt;br&gt;
if &lt;strong&gt;name&lt;/strong&gt; == "&lt;strong&gt;main&lt;/strong&gt;":&lt;br&gt;
   print(&lt;br&gt;
      find_no_in_list([1,&lt;br&gt;
                         2,&lt;br&gt;
                         3,&lt;br&gt;
                         4],&lt;br&gt;
                        3)&lt;br&gt;
      )&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After running the following command in terminal&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;$  black black_test.py&lt;br&gt;
Output file:&lt;br&gt;
def find_no_in_list(s, no):&lt;br&gt;
    s = list(s)&lt;br&gt;
    for i in range(len(s) - 1):&lt;br&gt;
        if s[i] == no:&lt;br&gt;
            return i&lt;br&gt;
    else:&lt;br&gt;
        return -1&lt;br&gt;
if &lt;strong&gt;name&lt;/strong&gt; == "&lt;strong&gt;main&lt;/strong&gt;":&lt;br&gt;
    print(find_no_in_list([1, 2, 3, 4], 3))&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's always a good practise to write a well formatted code so that it will easier to understand and manage in future so Black is must to have in your IDE when working with python so that you have a well formatted code everytime automatically.&lt;br&gt;
Next read &lt;a href="https://dev.to/djangochain/demystifying-pythons-style-guide-pep-8-j7k"&gt;understand pep8&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>codequality</category>
      <category>codereview</category>
    </item>
  </channel>
</rss>
