<?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: Pawan Jain</title>
    <description>The latest articles on DEV Community by Pawan Jain (@pawangeek).</description>
    <link>https://dev.to/pawangeek</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%2F433157%2Fcbc1a0a2-c8b0-43b7-bfb7-a01e4b3eb30e.png</url>
      <title>DEV Community: Pawan Jain</title>
      <link>https://dev.to/pawangeek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pawangeek"/>
    <language>en</language>
    <item>
      <title>5 NLP Libraries Everyone Should Know</title>
      <dc:creator>Pawan Jain</dc:creator>
      <pubDate>Wed, 05 Jan 2022 12:49:44 +0000</pubDate>
      <link>https://dev.to/pawangeek/5-nlp-libraries-everyone-should-know-2m51</link>
      <guid>https://dev.to/pawangeek/5-nlp-libraries-everyone-should-know-2m51</guid>
      <description>&lt;p&gt;In this guide, we’ll be touring the essential stack of Python NLP libraries.&lt;/p&gt;

&lt;p&gt;These packages handle a wide range of tasks such as part-of-speech (POS) tagging, dependency parsing, document classification, topic modelling, and much more.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The fundamental aim of NLP libraries is to simplify text preprocessing&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are many tools and libraries created to solve NLP problems… but you’ll cover all the essential bases once you master a handful of them. That’s why I decided to feature the Five Python NLP libraries I’ve found to be the most useful.&lt;/p&gt;

&lt;p&gt;But before that, you should have some basic knowledge about various components and topics of NLP&lt;/p&gt;

&lt;h2&gt;
  
  
  For Foundation
&lt;/h2&gt;

&lt;p&gt;There are some well-known, top-notch mainstay resources for the theoretical depth of Natural Language Processing&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stanford Course&lt;/strong&gt; — &lt;a href="http://web.stanford.edu/class/cs224n/"&gt;Natural Language Processing with Deep Learning&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deeplearning.ai Specialization&lt;/strong&gt; — &lt;a href="https://www.coursera.org/specializations/natural-language-processing"&gt;Natural Language Processing Specialization&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Best book for FUNDAMENTALS&lt;/strong&gt; (aka Bible of NLP) — &lt;a href="https://web.stanford.edu/~jurafsky/slp3/"&gt;Introduction to Natural Language Processing, Speech Recognition, and Computational Linguistics&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Another Good reference book&lt;/strong&gt; — &lt;a href="https://nlp.stanford.edu/fsnlp/"&gt;Foundations of Statistical Natural Language Processing&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Spacy Library
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://spacy.io/"&gt;spaCy&lt;/a&gt; is a well-known and straightforward natural language processing library in Python. It contributes to state-of-the-art efficiency and agility and has a proactive open-source association.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plus points&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interface well with all major deep learning frameworks and comes with some outstanding and useful language models pre-installed&lt;/li&gt;
&lt;li&gt;Comparatively faster because of &lt;a href="https://cython.org/"&gt;Cython&lt;/a&gt; support&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The best things you can do with spaCy
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Part-of-speech (POS) Tagging&lt;/strong&gt;: It is the process of appointing grammatical properties like a noun, verb, adjective, adverb, etc. to words&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Entity Recognition&lt;/strong&gt;: The primary method of labeling named entities discovered in the text into the pre-defined group&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dependency Parsing&lt;/strong&gt;: Assigning syntactic dependency labels, describing the relations between individual tokens, like subject or object.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Text Classification&lt;/strong&gt;: Assigning categories or labels to a whole document, or parts of a document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentence Boundary Detection (SBD)&lt;/strong&gt;: Finding and segmenting individual sentences.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Resources&lt;/p&gt;

&lt;p&gt;Here is the link for there free Official Course: &lt;a href="https://course.spacy.io/en/"&gt;Advanced NLP with spaCy&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More resources&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A good blog post including installation process and other Spacy uses (Get started blog): &lt;a href="https://realpython.com/natural-language-processing-spacy-python/"&gt;Natural Language Processing With spaCy in Python&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Intro to Spacy in Python (Videos) — &lt;a href="https://spacy.io/universe/category/videos"&gt;Talks and tutorials in video format&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. NLTK Toolkit
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.nltk.org/"&gt;NLTK&lt;/a&gt; is one of the most excellent libraries available out there to train NLP models. This library is elementary to use. It is a beginner-friendly library for NLP. It has a lot of pre-trained models and corpora, which helps us to analyze things very quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plus point&lt;/strong&gt;: Built-in support for dozens of corpora and trained models&lt;/p&gt;

&lt;h3&gt;
  
  
  The best things you can do with NLTK?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Recommendation&lt;/strong&gt;: Recommendation of content can be made based on the similarity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sentiment Analysis&lt;/strong&gt;: It measures the inclination of people’s opinions through natural language processing&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Wordnet[1] Support&lt;/strong&gt;: We can use Synset to look up words in WordNet. And hence access to homonyms, Hypernyms, synonyms, definitions, family, etc. of many words&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Machine Translation&lt;/strong&gt;: Used to translate source content into target languages&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Resources&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Best source for learning NLTK is their book: &lt;a href="https://www.nltk.org/book/"&gt;&lt;strong&gt;Analyzing Text with the Natural Language Toolkit&lt;/strong&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Good collection for related articles: &lt;strong&gt;&lt;a href="https://www.guru99.com/nltk-tutorial.html"&gt;NLTK (Natural Language Toolkit) Tutorial in Python&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Wordnet Docs — &lt;strong&gt;&lt;a href="https://wordnet.princeton.edu/documentation"&gt;WordNet 3.0 Reference Manual
&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Unlike spaCy which focuses on providing software for production usage, NLTK is widely used for teaching and research — &lt;a href="https://en.wikipedia.org/wiki/SpaCy"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  3. Transformers
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;&lt;a href="https://github.com/huggingface/transformers"&gt;transformers&lt;/a&gt;&lt;/strong&gt; library is an open-source, community-based repository to train, use and share models based on the Transformer architecture[2] such as Bert[3], Roberta[4], GPT2[5], XLNet[6], etc.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The library downloads pre-trained models for Natural Language Understanding (NLU) and Natural Language Generation (NLG) tasks&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Plus point&lt;/strong&gt;: Over 32+ pre-trained models in 100+ languages and deep interoperability between TensorFlow 2.0 and PyTorch. Best for deep learning&lt;/p&gt;

&lt;h3&gt;
  
  
  The best things you can do with Transformers
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Summarization&lt;/strong&gt;: Summarization is the task of summarizing a text / an article into a shorter text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Translation&lt;/strong&gt;: Task of translating a text from one language to another.
3.** Text Generation**: The goal is to create a coherent portion of text that is a continuation of the given context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extractive Question Answering&lt;/strong&gt;: Task of extracting an answer from a text given a question.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Official Docs — &lt;strong&gt;&lt;a href="https://huggingface.co/transformers/"&gt;Huggingface Transformers&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Building question-answering API with BERT, HuggingFace, and AWS Lambda — &lt;strong&gt;&lt;a href="https://towardsdatascience.com/serverless-bert-with-huggingface-and-aws-lambda-625193c6cc04"&gt;Serverless BERT with HuggingFace and AWS Lambda&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Learn how to fine-tune BERT for sentiment analysis — &lt;strong&gt;&lt;a href="https://www.curiousily.com/posts/sentiment-analysis-with-bert-and-hugging-face-using-pytorch-and-python/"&gt;Sentiment Analysis with BERT and Transformers&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Gensim Package
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/RaRe-Technologies/gensim"&gt;Gensim&lt;/a&gt;&lt;/strong&gt; is a Python library that specializes in identifying semantic similarity between two documents through vector space modeling and topic modeling toolkit&lt;/p&gt;

&lt;p&gt;By the way, it’s abbreviated for “Generate Similar” (Gensim) :)&lt;br&gt;
Plus Point: High-level processing speed and the ability to handle large amounts of Text.&lt;/p&gt;

&lt;h3&gt;
  
  
  The best things you can do with Gensim
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Distributed computing&lt;/strong&gt;: It can able to run Latent Semantic Analysis and Latent Dirichlet Allocation on a cluster of computers. (Reason for handling the massive amount of data)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Document indexing&lt;/strong&gt;: Process of associating the information with a file or specific tag allowing it to be easily retrieved later&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Topic Modelling&lt;/strong&gt;: Automatically clustering word groups and similar expressions that best defines a set of documents.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Similarity retrieval&lt;/strong&gt;: Deals with the organization, storage, retrieval and evaluation of similar information from document repositories (here textual information)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Official API Documentation — &lt;strong&gt;&lt;a href="https://radimrehurek.com/gensim/apiref.html"&gt;API Reference&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Official Tutorials — &lt;strong&gt;&lt;a href="https://radimrehurek.com/gensim/auto_examples/"&gt;Core tutorials&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Using Gensim LDA for hierarchical document clustering — &lt;strong&gt;&lt;a href="http://brandonrose.org/clustering#Latent-Dirichlet-Allocation"&gt;Document Clustering with Python&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Beginner tutorial for Installing, handling, etc. — &lt;strong&gt;&lt;a href="https://stackabuse.com/python-for-nlp-working-with-the-gensim-library-part-1/"&gt;Python for NLP: Working with the Gensim Library&lt;/a&gt;&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. Stanza
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://stanfordnlp.github.io/stanza/"&gt;Stanza[7]&lt;/a&gt;&lt;/strong&gt; is a collection of accurate and efficient tools for many human languages in one place. Starting from raw text to syntactic analysis and entity recognition, Stanza brings state-of-the-art NLP models to languages&lt;/p&gt;

&lt;p&gt;The toolkit is built on top of the PyTorch library with support for using GPU and pre-trained neural models.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In addition, Stanza includes a Python interface to the &lt;strong&gt;&lt;a href="https://stanfordnlp.github.io/CoreNLP"&gt;CoreNLP Java package&lt;/a&gt;&lt;/strong&gt; and inherits additional functionality from there&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Plus point&lt;/strong&gt;: It’s fast, accurate, and able to support several major languages. Suitable for product implementations&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resource&lt;/strong&gt;: Here is the &lt;strong&gt;&lt;a href="http://stanfordnlp.github.io/CoreNLP/other-languages.html#python"&gt;List of Python wrappers for CoreNLP&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The best things you can do with Stanza
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Morphological Feature Tagging&lt;/strong&gt;: For each word in a sentence, Stanza evaluates its universal morphological features (e.g., singular/plural, 1st/2nd/3rd person, among others).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Multi-Word Token Expansion&lt;/strong&gt;: Extending sentence split into the syntactic words as the foundation for downstream processing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The innate characteristics of these five libraries make it a top choice for any project that relies on machine understanding of human expressions.&lt;/p&gt;

&lt;p&gt;Thank you for reading. Don’t hesitate to stay tuned for more! Is there any other foundational or essential library? Let me know in the comments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Footnotes
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://wordnetcode.princeton.edu/5papers.pdf"&gt;Introduction to WordNet&lt;/a&gt;: An On-line Lexical Database — George A. Miller &amp;amp; al. 1993&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/abs/1706.03762"&gt;Attention Is All You Need&lt;/a&gt; — Vaswani &amp;amp; al., 2017&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/abs/1810.04805"&gt;BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding&lt;/a&gt; — Devlin &amp;amp; al., 2018&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/abs/1907.11692"&gt;RoBERTa: A Robustly Optimized BERT Pretraining Approach&lt;/a&gt; — Liu &amp;amp; al., 2019&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/abs/1907.11692"&gt;Language Models are Unsupervised Multitask Learners(GPT2)&lt;/a&gt; — Radford &amp;amp; al., 2019&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/abs/1906.08237"&gt;XLNet: Generalized Autoregressive Pretraining for Language Understanding&lt;/a&gt; — Yang &amp;amp; al., 2019&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://arxiv.org/abs/2003.07082"&gt;Stanza: A Python Natural Language Processing Toolkit for Many Human Languages&lt;/a&gt; — Peng &amp;amp; al., 2020&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>nlp</category>
      <category>python</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why doesn’t Python have a main function?</title>
      <dc:creator>Pawan Jain</dc:creator>
      <pubDate>Fri, 24 Jul 2020 04:58:40 +0000</pubDate>
      <link>https://dev.to/pawangeek/why-doesn-t-python-have-a-main-function-2lfp</link>
      <guid>https://dev.to/pawangeek/why-doesn-t-python-have-a-main-function-2lfp</guid>
      <description>&lt;h1&gt;
  
  
  Why don’t I recommend it either
&lt;/h1&gt;

&lt;p&gt;There is no doubt that there is no so-called main entry function in Python, but there are often articles on the Internet that mention &lt;strong&gt;“Python’s main function” and “suggest to write the main function.”&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Their intention may be to imitate the authentic main functions, but many people are misled (or misunderstood) and write very cumbersome code.&lt;/p&gt;

&lt;p&gt;In this story, we will talk about Why Python does not have the main function?.&lt;/p&gt;

&lt;p&gt;Before starting the topic, let’s answer these two questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;What does the so-called “main function” mean?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Why do some programming languages ​​need to force writing a main function?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some programming languages ​​use the main function as the execution entry of the program, such as C/C++, C#, Java, Go, Rust, etc., which have specific meanings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This main function name is mandatory, which means that there must be a primary function.&lt;/li&gt;
&lt;li&gt;There can be at most one main function, which means that the entry to the program is unique.&lt;/li&gt;
&lt;li&gt;The grammar format has specific requirements, with a relatively fixed template.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why do you have to force a main entry function?
&lt;/h2&gt;

&lt;p&gt;These languages are compiled languages, which require code to be compiled into executable binaries in order for the operating system/bootloader to find The start of the program, so you need to define this one function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Simply, there is a significant beginning that needs to be defined in a large pile of code that can be used for execution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is not difficult to see that the main function is an essential and indispensable organic part of those languages.&lt;br&gt;
However, when we look at Python again, the situation is quite different.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Python is an interpreted language, i.e., a scripting language. The running process is from top to bottom, line by line, which means that its starting point is known.&lt;/li&gt;
&lt;li&gt;Each .py file is an executable file, which can be used as the entry file of the entire program, implies the entry of the program is flexible, and no convention must be followed&lt;/li&gt;
&lt;li&gt;Sometimes running the Python project, did not specify the entry file (the command line more common, such as “&lt;code&gt;python -m http.server 8000&lt;/code&gt;”), it may be the presence of &lt;code&gt;main.py&lt;/code&gt; file, it is in the package as a "file" to perform the operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, it means that the scripting language Python is different from the compiled language. Whether it is at the level of a single module (that is, a .py file), or at the package level composed of multiple modules, &lt;strong&gt;it can choose a flexible execution method&lt;/strong&gt;, Unlike other languages ​​that cannot be implemented without a well-defined entry.&lt;/p&gt;

&lt;p&gt;In other words, Python does not need to stipulate that the programmer must define a unified entry (whether it is a function or a class or something) at the syntax level.&lt;/p&gt;

&lt;p&gt;Some people may be confused because they often see or write the following code themselves:&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;# main file
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="err"&gt;……&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;q&gt;Isn’t this the main function of Python? I believe many of us think so!&lt;/q&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;No, It’s not&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Except that the function name is “main” it does not have a half-cent relationship with the orthodox main function we introduced earlier, neither mandatory nor necessarily determining the order of program execution. Without it, it will not cause any grammatical problems.&lt;/p&gt;

&lt;p&gt;The reason why some people want to name a “main” function is actually to emphasize its “main” status and wants to arrange it as the first function to executed artificially.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They may think that such named functions are easier to remember.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The reason why they want to write &lt;code&gt;if &lt;strong&gt;name&lt;/strong&gt; == '&lt;strong&gt;main&lt;/strong&gt;'&lt;/code&gt;, may want to show that main() only runs when the current script is directly executed and doesn’t want to be run when it is imported into other modules.&lt;/p&gt;

&lt;p&gt;However, I personally do not recommend this way of writing&lt;/p&gt;

&lt;p&gt;The most obvious example: there are only a few dozen lines of code or just a script file that implements a simple function (a small crawler, drawing a picture with a turtle, etc.), but they’re all written in the same style as before.&lt;/p&gt;

&lt;p&gt;It is not recommended to write &lt;code&gt;if name__ == '__main'&lt;/code&gt; because of the following reasons.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First of all, if there is only one file because there is no possibility of export.&lt;/li&gt;
&lt;li&gt;Secondly, if there are multiple files, it is highly discouraged to write this sentence in the entry file (main.py). Theoretically, its content shouldn’t be exported for use in other modules, since it’s the starting point.&lt;/li&gt;
&lt;li&gt;Finally, it is also not recommended to write this judgment in non-entry files with multiple files, as the most that can be done is to write some of these test codes. Still, the test code should be separated and written in a dedicated directory or file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every time I see this cumbersome code without thinking, I feel uncomfortable. Why write that if statement? If possible, you should split the main function without even wrapping it into a function!&lt;/p&gt;

&lt;h2&gt;
  
  
  To sum up
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Break inertial thinking and write authentic code. The main entry function is unique to some languages, and should not be used in Python. You should understand the characteristics of the scripting language and write a simple and elegant style.&lt;/li&gt;
&lt;li&gt;Use main.py instead of main(). Because the program execution unit of Python is a script file, not a function or class, it is recommended to name the entry file main.py, and the internal functions are determined according to requirements.&lt;/li&gt;
&lt;li&gt;If possible, use main.py as an entry file. This file is straightforward to use in combination with the "-m" parameter on the command line.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How do you feel about after reading this article? Do you like to use that if statement? Let me know in comments with the reason 😊&lt;/p&gt;

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