<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Geeker on Medium]]></title>
        <description><![CDATA[Stories by Geeker on Medium]]></description>
        <link>https://medium.com/@geekerpro?source=rss-48359887a55a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1BJ0Wvh1mxjBryN5iQSs_g.png</url>
            <title>Stories by Geeker on Medium</title>
            <link>https://medium.com/@geekerpro?source=rss-48359887a55a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:09:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@geekerpro/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[You NEED to change this in your python code!]]></title>
            <link>https://medium.com/@geekerpro/you-need-to-change-this-in-your-python-code-90f1b146f208?source=rss-48359887a55a------2</link>
            <guid isPermaLink="false">https://medium.com/p/90f1b146f208</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Geeker]]></dc:creator>
            <pubDate>Fri, 29 Apr 2022 22:27:13 GMT</pubDate>
            <atom:updated>2022-04-29T22:27:13.594Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/284/1*h7OAzx_jX7jB_AbNI5cNoQ.jpeg" /></figure><p>So… you want to become a python pro. Something to show off… I mean.. make your python code BEAUTIFULL. Whatever you choose, you need this change in your code. It is really important, and putting this in your code/project, it will throw off all the python noobs and attract all the python pros.</p><p>So what is this tip? Well lets give you an example. Here is some basic code, this just asks the user two numbers and then adds them. Pretty simple.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*efBF_oqwcZyC1hz5S76y-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*Enyi9yUoAltCZbG6iNSnGw.png" /></figure><p>Now, lets put this in a function and then run it that way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*Xl7lOWx53VzR_FpfVFTtyg.png" /></figure><p>This will give the same output.</p><p>Now, the problem arises when you try to import this file. Lets create a new python file, for this example, I am going to call it file2.py. The first file is called main.py.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*cUdKiOKeHXcGW7kpaPTMPA.png" /></figure><p>Note: The program will run twice as in the main file the main function is called.</p><p>This will also run. But, if you are creating a program, you don’t want your program to be ran if it is imported. So is there a way to fix this? YES! there is a very simple way to make that happen!</p><p>There is something special in python called __name__ it sounds racist to British people, and well… it may be? who knows, but if you print it it should give you the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*NRCGOSq7XBe7uwyKBib1GA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/112/1*pGXCklF_SwWBDVFqo-Sjvg.png" /></figure><p>Now, this is something we can use. Because it only prints __main__ if the file is ran. If it is imported, then it won’t be ran. So any geeks out there, you can already figure this out. We can edit our main program. If the __name__ is __main__ then we run the main module. With this info, if the file is imported, it won’t be ran.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*hmLbadamLJOoVCRvasNA7w.png" /></figure><p>And the program runs fine.</p><p>Now, this is really useful for people making scripts, something that will run. If you have a file that you need to import, this won’t really help you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=90f1b146f208" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>