__all__ in Python and What It Does
<p>Let’s say we have 2 Python scripts.</p>
<ul>
<li>main.py — the script that we want to run</li>
<li>helper.py — main.py imports stuff from this script</li>
<li>these 2 scripts are in the same folder</li>
</ul>
<pre>
# helper.py
a = 4
b = 5
c = 6
def test():
print('test')</pre>
<pre>
# main.py
from helper import *
print(a, b, c) # 4 5 6
test() # test</pre>
<ul>
<li>In main.py, the line <code>from helper import *</code> means that <em>everything </em>inside helper.py is imported into main.py</li>
<li>this is why we can use <code>a</code> <code>b</code> <code>c</code> and <code>test</code> in main.py</li>
</ul>
<h1>What if I want to do a partial import?</h1>
<p>Let’s say instead of import <code>a</code> <code>b</code> <code>c</code> and <code>test</code>, I only wish to import <code>a</code> and <code>b</code> only. In main.py, we can change up the <code>from helper import *</code> statement.</p>
<pre>
# helper.py
a = 4
b = 5
c = 6
def test():
print('test')</pre>
<pre>
# main.py
from helper import a, b
print(a, b) # 4 5
# attempting to use c or test will cause error</pre>
<ul>
<li>the statement <code>from helper import a, b</code> imports ONLY <code>a</code> and <code>b</code> from helper.py — <code>c</code> and <code>test</code> are not imported.</li>
<li>this is how we can partial import</li>
</ul>
<p><a href="https://levelup.gitconnected.com/all-in-python-and-what-it-does-fb08a9f0a884">Click Here</a> </p>