{"id":1046,"date":"2022-08-20T21:12:10","date_gmt":"2022-08-20T15:42:10","guid":{"rendered":"https:\/\/jassweb.com\/new22\/solved-what-does-if-__name__-__main__-do\/"},"modified":"2022-08-20T21:12:10","modified_gmt":"2022-08-20T15:42:10","slug":"solved-what-does-if-__name__-__main__-do-2","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/","title":{"rendered":"(Solved) What does if __name__ == \u201c__main__\u201d: do?"},"content":{"rendered":"<h2> Introduction <\/h2>\n<p>[ad_1]<\/p>\n<p>If __name__ == &#8220;__main__&#8221;: is a special statement in Python that is used to execute some code only if the file is run directly. This statement is used to check whether the current file is being imported from another module or not. If the file is being imported from another module, the code inside the if statement will not be executed. If the file is being run directly, the code inside the if statement will be executed. This statement is useful for organizing code and making sure that certain code is only executed when the file is run directly.<\/p>\n<h2> Solution<\/h2>\n<p><\/p>\n<p>The statement if __name__ == &#8220;__main__&#8221;: is used to execute some code only if the file containing it is being run directly. This statement is used to check if the file is being imported from another module or if it is being run directly. If the file is being run directly, the code within the if statement will be executed. If the file is being imported from another module, the code within the if statement will not be executed. <\/p>\n<p><\/p>\n<div class=\"entry-content\" itemprop=\"text\">\n<script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1088640234840270\" crossorigin=\"anonymous\"><\/script><\/p>\n<p><script><\/p>\n<p><\/script><\/p>\n<p>\n<\/p>\n<div id=\"answer-419185\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"419185\" data-parentid=\"419163\" data-score=\"8355\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<h1>Short Answer<\/h1>\n<p>It\u2019s boilerplate code that protects users from accidentally invoking the script when they didn\u2019t intend to. Here are some common problems when the guard is omitted from a script:<\/p>\n<ul>\n<li>\n<p>If you import the guardless script in another script (e.g. <code>import my_script_without_a_name_eq_main_guard<\/code>), then the latter script will trigger the former to run <em>at import time<\/em> and <em>using the second script\u2019s command line arguments<\/em>. This is almost always a mistake.<\/p>\n<\/li>\n<li>\n<p>If you have a custom class in the guardless script and save it to a pickle file, then unpickling it in another script will trigger an import of the guardless script, with the same problems outlined in the previous bullet.<\/p>\n<\/li>\n<\/ul>\n<h1>Long Answer<\/h1>\n<p>To better understand why and how this matters, we need to take a step back to understand how Python initializes scripts and how this interacts with its module import mechanism.<\/p>\n<p>Whenever the Python interpreter reads a source file, it does two things:<\/p>\n<ul>\n<li>\n<p>it sets a few special variables like <code>__name__<\/code>, and then<\/p>\n<\/li>\n<li>\n<p>it executes all of the code found in the file.<\/p>\n<\/li>\n<\/ul>\n<p>Let\u2019s see how this works and how it relates to your question about the <code>__name__<\/code> checks we always see in Python scripts.<\/p>\n<h2>Code Sample<\/h2>\n<p>Let\u2019s use a slightly different code sample to explore how imports and scripts work. Suppose the following is in a file called <code>foo.py<\/code>.<\/p>\n<pre><code># Suppose this is foo.py.\n\nprint(\"before import\")\nimport math\n\nprint(\"before function_a\")\ndef function_a():\n    print(\"Function A\")\n\nprint(\"before function_b\")\ndef function_b():\n    print(\"Function B {}\".format(math.sqrt(100)))\n\nprint(\"before __name__ guard\")\nif __name__ == '__main__':\n    function_a()\n    function_b()\nprint(\"after __name__ guard\")\n<\/code><\/pre>\n<h2>Special Variables<\/h2>\n<p>When the Python interpreter reads a source file, it first defines a few special variables. In this case, we care about the <code>__name__<\/code> variable.<\/p>\n<p><strong>When Your Module Is the Main Program<\/strong><\/p>\n<p>If you are running your module (the source file) as the main program, e.g.<\/p>\n<pre><code>python foo.py\n<\/code><\/pre>\n<p>the interpreter will assign the hard-coded string <code>\"__main__\"<\/code> to the <code>__name__<\/code> variable, i.e.<\/p>\n<pre><code># It's as if the interpreter inserts this at the top\n# of your module when run as the main program.\n__name__ = \"__main__\" \n<\/code><\/pre>\n<p><strong>When Your Module Is Imported By Another<\/strong><\/p>\n<p>On the other hand, suppose some other module is the main program and it imports your module. This means there\u2019s a statement like this in the main program, or in some other module the main program imports:<\/p>\n<pre><code># Suppose this is in some other main program.\nimport foo\n<\/code><\/pre>\n<p>The interpreter will search for your <code>foo.py<\/code> file (along with searching for a few other variants), and prior to executing that module, it will assign the name <code>\"foo\"<\/code> from the import statement to the <code>__name__<\/code> variable, i.e.<\/p>\n<pre><code># It's as if the interpreter inserts this at the top\n# of your module when it's imported from another module.\n__name__ = \"foo\"\n<\/code><\/pre>\n<h2>Executing the Module\u2019s Code<\/h2>\n<p>After the special variables are set up, the interpreter executes all the code in the module, one statement at a time. You may want to open another window on the side with the code sample so you can follow along with this explanation.<\/p>\n<p><strong>Always<\/strong><\/p>\n<ol>\n<li>\n<p>It prints the string <code>\"before import\"<\/code> (without quotes).<\/p>\n<\/li>\n<li>\n<p>It loads the <code>math<\/code> module and assigns it to a variable called <code>math<\/code>. This is equivalent to replacing <code>import math<\/code> with the following (note that <code>__import__<\/code> is a low-level function in Python that takes a string and triggers the actual import):<\/p>\n<\/li>\n<\/ol>\n<pre><code># Find and load a module given its string name, \"math\",\n# then assign it to a local variable called math.\nmath = __import__(\"math\")\n<\/code><\/pre>\n<ol start=\"3\">\n<li>\n<p>It prints the string <code>\"before function_a\"<\/code>.<\/p>\n<\/li>\n<li>\n<p>It executes the <code>def<\/code> block, creating a function object, then assigning that function object to a variable called <code>function_a<\/code>.<\/p>\n<\/li>\n<li>\n<p>It prints the string <code>\"before function_b\"<\/code>.<\/p>\n<\/li>\n<li>\n<p>It executes the second <code>def<\/code> block, creating another function object, then assigning it to a variable called <code>function_b<\/code>.<\/p>\n<\/li>\n<li>\n<p>It prints the string <code>\"before __name__ guard\"<\/code>.<\/p>\n<\/li>\n<\/ol>\n<p><strong>Only When Your Module Is the Main Program<\/strong><\/p>\n<ol start=\"8\">\n<li>If your module is the main program, then it will see that <code>__name__<\/code> was indeed set to <code>\"__main__\"<\/code> and it calls the two functions, printing the strings <code>\"Function A\"<\/code> and <code>\"Function B 10.0\"<\/code>.<\/li>\n<\/ol>\n<p><strong>Only When Your Module Is Imported by Another<\/strong><\/p>\n<ol start=\"8\">\n<li>(<strong>instead<\/strong>) If your module is not the main program but was imported by another one, then <code>__name__<\/code> will be <code>\"foo\"<\/code>, not <code>\"__main__\"<\/code>, and it\u2019ll skip the body of the <code>if<\/code> statement.<\/li>\n<\/ol>\n<p><strong>Always<\/strong><\/p>\n<ol start=\"9\">\n<li>It will print the string <code>\"after __name__ guard\"<\/code> in both situations.<\/li>\n<\/ol>\n<p><em><strong>Summary<\/strong><\/em><\/p>\n<p>In summary, here\u2019s what\u2019d be printed in the two cases:<\/p>\n<pre class=\"lang-none prettyprint-override\"><code># What gets printed if foo is the main program\nbefore import\nbefore function_a\nbefore function_b\nbefore __name__ guard\nFunction A\nFunction B 10.0\nafter __name__ guard\n<\/code><\/pre>\n<pre class=\"lang-none prettyprint-override\"><code># What gets printed if foo is imported as a regular module\nbefore import\nbefore function_a\nbefore function_b\nbefore __name__ guard\nafter __name__ guard\n<\/code><\/pre>\n<h2>Why Does It Work This Way?<\/h2>\n<p>You might naturally wonder why anybody would want this. Well, sometimes you want to write a <code>.py<\/code> file that can be both used by other programs and\/or modules as a module, and can also be run as the main program itself. Examples:<\/p>\n<ul>\n<li>\n<p>Your module is a library, but you want to have a script mode where it runs some unit tests or a demo.<\/p>\n<\/li>\n<li>\n<p>Your module is only used as a main program, but it has some unit tests, and the testing framework works by importing <code>.py<\/code> files like your script and running special test functions. You don\u2019t want it to try running the script just because it\u2019s importing the module.<\/p>\n<\/li>\n<li>\n<p>Your module is mostly used as a main program, but it also provides a programmer-friendly API for advanced users.<\/p>\n<\/li>\n<\/ul>\n<p>Beyond those examples, it\u2019s elegant that running a script in Python is just setting up a few magic variables and importing the script. \u201cRunning\u201d the script is a side effect of importing the script\u2019s module.<\/p>\n<h2>Food for Thought<\/h2>\n<ul>\n<li>\n<p>Question: Can I have multiple <code>__name__<\/code> checking blocks? Answer: it\u2019s strange to do so, but the language won\u2019t stop you.<\/p>\n<\/li>\n<li>\n<p>Suppose the following is in <code>foo2.py<\/code>. What happens if you say <code>python foo2.py<\/code> on the command-line? Why?<\/p>\n<\/li>\n<\/ul>\n<pre class=\"lang-py prettyprint-override\"><code># Suppose this is foo2.py.\nimport os, sys; sys.path.insert(0, os.path.dirname(__file__)) # needed for some interpreters\n\ndef function_a():\n    print(\"a1\")\n    from foo2 import function_b\n    print(\"a2\")\n    function_b()\n    print(\"a3\")\n\ndef function_b():\n    print(\"b\")\n\nprint(\"t1\")\nif __name__ == \"__main__\":\n    print(\"m1\")\n    function_a()\n    print(\"m2\")\nprint(\"t2\")\n      \n<\/code><\/pre>\n<ul>\n<li>Now, figure out what will happen if you remove the <code>__name__<\/code> check in <code>foo3.py<\/code>:<\/li>\n<\/ul>\n<pre class=\"lang-py prettyprint-override\"><code># Suppose this is foo3.py.\nimport os, sys; sys.path.insert(0, os.path.dirname(__file__)) # needed for some interpreters\n\ndef function_a():\n    print(\"a1\")\n    from foo3 import function_b\n    print(\"a2\")\n    function_b()\n    print(\"a3\")\n\ndef function_b():\n    print(\"b\")\n\nprint(\"t1\")\nprint(\"m1\")\nfunction_a()\nprint(\"m2\")\nprint(\"t2\")\n<\/code><\/pre>\n<ul>\n<li>What will this do when used as a script? When imported as a module?<\/li>\n<\/ul>\n<pre class=\"lang-py prettyprint-override\"><code># Suppose this is in foo4.py\n__name__ = \"__main__\"\n\ndef bar():\n    print(\"bar\")\n    \nprint(\"before __name__ guard\")\nif __name__ == \"__main__\":\n    bar()\nprint(\"after __name__ guard\")\n<\/code><\/pre>\n<\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p> <span class=\"d-none\" itemprop=\"commentCount\">21<\/span> <\/p>\n<\/div>\n<\/div>\n<p>solved What does if __name__ == \u201c__main__\u201d: do? <\/p>\n<p><script async src=\"https:\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-1088640234840270\" crossorigin=\"anonymous\"><\/script><\/p>\n<p><script><\/p>\n<p><\/script> <\/div>\n<p>[ad_2]<\/p>\n<p>If you&#8217;ve ever written a Python program, you may have seen the statement <code>if __name__ == \"__main__\":<\/code> at the bottom of the code. But what does this statement do?<\/p>\n<p>The <code>if __name__ == \"__main__\"<\/code> statement is used to execute some code only if the file containing it is being run directly. It is a special variable in Python that is set to <code>\"__main__\"<\/code> when the program is being run directly, but is set to the name of the module when the program is being imported from another module.<\/p>\n<p>This statement is useful for organizing code into modules that can be imported and used in other programs. For example, if you have a module containing a function that you want to use in multiple programs, you can put the function in a separate file and import it into the other programs. The <code>if __name__ == \"__main__\"<\/code> statement can be used to make sure that the code in the module is only executed when the module is run directly, and not when it is imported.<\/p>\n<p>In summary, the <code>if __name__ == \"__main__\"<\/code> statement is used to execute code only when the file containing it is being run directly, and not when it is imported from another module. This is useful for organizing code into modules that can be imported and used in other programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction [ad_1] If __name__ == &#8220;__main__&#8221;: is a special statement in Python that is used to execute some code only if the file is run directly. This statement is used to check whether the current file is being imported from another module or not. If the file is being imported from another module, the code &#8230; <a title=\"(Solved) What does if __name__ == \u201c__main__\u201d: do?\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\" aria-label=\"More on (Solved) What does if __name__ == \u201c__main__\u201d: do?\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[411,406,409,349,410],"class_list":["post-1046","post","type-post","status-publish","format-standard","hentry","category-solved","tag-idioms","tag-namespaces","tag-program-entry-point","tag-python","tag-python-module"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>(Solved) What does if __name__ == \u201c__main__\u201d: do? - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"(Solved) What does if __name__ == \u201c__main__\u201d: do? - JassWeb\" \/>\n<meta property=\"og:description\" content=\"Introduction [ad_1] If __name__ == &#8220;__main__&#8221;: is a special statement in Python that is used to execute some code only if the file is run directly. This statement is used to check whether the current file is being imported from another module or not. If the file is being imported from another module, the code ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-20T15:42:10+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"(Solved) What does if __name__ == \u201c__main__\u201d: do?\",\"datePublished\":\"2022-08-20T15:42:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\"},\"wordCount\":1227,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"idioms\",\"namespaces\",\"program-entry-point\",\"python\",\"python-module\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\",\"name\":\"(Solved) What does if __name__ == \u201c__main__\u201d: do? - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-08-20T15:42:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"(Solved) What does if __name__ == \u201c__main__\u201d: do?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"(Solved) What does if __name__ == \u201c__main__\u201d: do? - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/","og_locale":"en_US","og_type":"article","og_title":"(Solved) What does if __name__ == \u201c__main__\u201d: do? - JassWeb","og_description":"Introduction [ad_1] If __name__ == &#8220;__main__&#8221;: is a special statement in Python that is used to execute some code only if the file is run directly. This statement is used to check whether the current file is being imported from another module or not. If the file is being imported from another module, the code ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/","og_site_name":"JassWeb","article_published_time":"2022-08-20T15:42:10+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"(Solved) What does if __name__ == \u201c__main__\u201d: do?","datePublished":"2022-08-20T15:42:10+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/"},"wordCount":1227,"commentCount":0,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["idioms","namespaces","program-entry-point","python","python-module"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/","url":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/","name":"(Solved) What does if __name__ == \u201c__main__\u201d: do? - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-08-20T15:42:10+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-what-does-if-__name__-__main__-do-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"(Solved) What does if __name__ == \u201c__main__\u201d: do?"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/1046","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=1046"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/1046\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=1046"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=1046"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=1046"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}