<?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 Himansu Sahoo on Medium]]></title>
        <description><![CDATA[Stories by Himansu Sahoo on Medium]]></description>
        <link>https://medium.com/@himansusahoo?source=rss-f0911117e8f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QewZM-IigwQNUnPBx75j5A.png</url>
            <title>Stories by Himansu Sahoo on Medium</title>
            <link>https://medium.com/@himansusahoo?source=rss-f0911117e8f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:37:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@himansusahoo/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[Three techniques to import a python module]]></title>
            <link>https://medium.com/@himansusahoo/three-techniques-to-import-a-python-module-621d327572d0?source=rss-f0911117e8f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/621d327572d0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Himansu Sahoo]]></dc:creator>
            <pubDate>Wed, 16 Jan 2019 17:45:00 GMT</pubDate>
            <atom:updated>2019-01-17T16:35:28.047Z</atom:updated>
            <content:encoded><![CDATA[<p>While working on a bigger project, main python module usually gets longer. Then one need to write separate small modules and import them in the main code. This will give access to the variables and functions defined in the imported module.</p><p>Sometimes, one may not know the python module name to import and would like to pass it as a parameter to the main module.</p><p>This article will focus different ways one can import a python module.</p><p>create a python module <strong><em>config.py</em></strong> with the following code.</p><blockquote>var = 10<br>def getval():<br> return 10+10</blockquote><p>Create another module <strong><em>program.py</em></strong>, to access the variable var and function getval() from the config file.<br>Three different ways you can do this.</p><p><strong>1 — Import config</strong></p><blockquote>import config<br>print(“var : “, config.var)<br>print(“result : “, config.getval())</blockquote><p><strong>2 — from config import var, getval</strong></p><p>one can directly import the variable and function.</p><blockquote>from config import var, getval<br>print(“var : “, var)<br>print(“result : “, getval())</blockquote><p>Notice that you don’t need the barckets while importing a function.</p><p><strong>3 — passing as a prameter</strong></p><p>Last one is interesting, if want to pass as a parameter while running the program.py. This is specially helpful if need to many configuration parameters.</p><blockquote>import sys<br>filename = sys.argv[1].split(“.”)[0]<br>config1 = __import__(filename)<br>print(“var1 : “, config1.var)<br>print(“result1 : “, config1.getval())</blockquote><p><em>To run this just type : python program.py config.py</em></p><p>You can get codes of this article from my github link:</p><p><a href="https://github.com/himansu979/MachineLearning_Resources/tree/master/import_module">himansu979/MachineLearning_Resources</a></p><p>I hope this helps to understand the import statements in python. <br>Please suggest if you come across any other methods. Thanks for reading.</p><p>References:</p><p><a href="http://effbot.org/zone/import-confusion.htm">http://effbot.org/zone/import-confusion.htm</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=621d327572d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>