<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Importing_Modules</id>
	<title>Importing Modules - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Importing_Modules"/>
	<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Importing_Modules&amp;action=history"/>
	<updated>2026-07-21T06:34:39Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Importing_Modules&amp;diff=331&amp;oldid=prev</id>
		<title>Davrot at 16:16, 17 October 2025</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Importing_Modules&amp;diff=331&amp;oldid=prev"/>
		<updated>2025-10-17T16:16:28Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:16, 17 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== The goal ==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Collections of functions can be organized into modules. These modules are then imported into a &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;program &lt;/ins&gt;or another module.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Collections of functions can be organized into modules. These modules are then imported into a &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;programm &lt;/del&gt;or another module.&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l51&quot;&gt;Line 51:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 50:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== [https://docs.python.org/3/tutorial/modules.html#more-on-modules as and from] ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== [https://docs.python.org/3/tutorial/modules.html#more-on-modules as and from] ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;blockquote&amp;gt;It can also be used when &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;utilising &lt;/del&gt;from with similar effects:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&quot;python&quot;&amp;gt;from fibo import fib as fibonacci&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;blockquote&amp;gt;It can also be used when &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;utilizing &lt;/ins&gt;from with similar effects:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&quot;python&quot;&amp;gt;from fibo import fib as fibonacci&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;fibonacci(500)&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;fibonacci(500)&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Importing_Modules&amp;diff=158&amp;oldid=prev</id>
		<title>Davrot: Created page with &quot; == The goal == Collections of functions can be organized into modules. These modules are then imported into a programm or another module.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == [https://docs.python.org/3/tutorial/modules.html Basics] == &lt;blockquote&gt;A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Importing_Modules&amp;diff=158&amp;oldid=prev"/>
		<updated>2025-10-15T13:44:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == The goal == Collections of functions can be organized into modules. These modules are then imported into a programm or another module.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == [https://docs.python.org/3/tutorial/modules.html Basics] == &amp;lt;blockquote&amp;gt;A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the v...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== The goal ==&lt;br /&gt;
Collections of functions can be organized into modules. These modules are then imported into a programm or another module.&lt;br /&gt;
&lt;br /&gt;
Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/tutorial/modules.html Basics] ==&lt;br /&gt;
&amp;lt;blockquote&amp;gt;A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended. Within a module, the module’s name (as a string) is available as the value of the global variable __name__. For instance, use your favorite text editor to create a file called fibo.py in the current directory with the following contents:&amp;lt;/blockquote&amp;gt;Let us assume we have a file with the name fibo.py and the following content in our working directory&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&amp;gt; def fib(n):    # write Fibonacci series up to n​&lt;br /&gt;
    a, b = 0, 1&lt;br /&gt;
&lt;br /&gt;
    while a &amp;lt; n:&lt;br /&gt;
        print(a, end=&amp;#039; &amp;#039;)&lt;br /&gt;
        a, b = b, a+b&lt;br /&gt;
    print()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def fib2(n):   # return Fibonacci series up to n​&lt;br /&gt;
    result = []&lt;br /&gt;
    a, b = 0, 1&lt;br /&gt;
&lt;br /&gt;
    while a &amp;lt; n:&lt;br /&gt;
        result.append(a)&lt;br /&gt;
        a, b = b, a+b&lt;br /&gt;
&lt;br /&gt;
    return result&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;We can now import this module with the following command&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import fibo&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;This does not enter the names of the functions defined in fibo directly in the current symbol table; it only enters the module name fibo there. Using the module name you can access the functions:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import fibo&lt;br /&gt;
&lt;br /&gt;
fibo.fib(1000) # -&amp;gt; 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 &lt;br /&gt;
&lt;br /&gt;
x = fibo.fib2(100) &lt;br /&gt;
print(x) # -&amp;gt; [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]&lt;br /&gt;
&lt;br /&gt;
print(fibo.__name__) # -&amp;gt; fibo&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;If you intend to use a function often you can assign it to a local name:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import fibo&lt;br /&gt;
&lt;br /&gt;
fib = fibo.fib&lt;br /&gt;
fib(500) # -&amp;gt; 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/tutorial/modules.html#more-on-modules from] ==&lt;br /&gt;
&amp;lt;blockquote&amp;gt;A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only the first time the module name is encountered in an import statement. (They are also run if the file is executed as a script.)&lt;br /&gt;
&lt;br /&gt;
Each module has its own private symbol table, which is used as the global symbol table by all functions defined in the module. Thus, the author of a module can use global variables in the module without worrying about accidental clashes with a user’s global variables. On the other hand, if you know what you are doing you can touch a module’s global variables with the same notation used to refer to its functions, modname.itemname.&lt;br /&gt;
&lt;br /&gt;
Modules can import other modules. It is customary but not required to place all import statements at the beginning of a module (or script, for that matter). The imported module names are placed in the importing module’s global symbol table.&amp;lt;/blockquote&amp;gt;&amp;lt;blockquote&amp;gt;There is a variant of the import statement that imports names from a module directly into the importing module’s symbol table. For example:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from fibo import fib, fib2&lt;br /&gt;
fib(500) # -&amp;gt; 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377&lt;br /&gt;
print(fib2(100))  #-&amp;gt; [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;This does not introduce the module name from which the imports are taken in the local symbol table (so in the example, fibo is not defined).&amp;lt;/blockquote&amp;gt;&amp;lt;blockquote&amp;gt;There is even a variant to import all names that a module defines:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from fibo import *&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;This imports all names except those beginning with an underscore (_).&amp;lt;/blockquote&amp;gt;&amp;#039;&amp;#039;&amp;#039;However, this is bad style!!! Don’t use “import *” or you are a bad person!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/tutorial/modules.html#more-on-modules as] ==&lt;br /&gt;
If the module name is followed by &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039;, then the name following as is bound directly to the imported module.&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import fibo as fib&lt;br /&gt;
fib.fib(500)&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;This is effectively importing the module in the same way that import fibo will do, with the only difference of it being available as fib.&amp;lt;/blockquote&amp;gt;Typical examples are:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import numpy as np&lt;br /&gt;
import pandas as pd&lt;br /&gt;
import matplotlib.pyplot as plt&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/tutorial/modules.html#more-on-modules as and from] ==&lt;br /&gt;
&amp;lt;blockquote&amp;gt;It can also be used when utilising from with similar effects:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from fibo import fib as fibonacci&lt;br /&gt;
fibonacci(500)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/tutorial/modules.html#more-on-modules Changing a loaded lib] ==&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;#039;&amp;#039;&amp;#039;Note&amp;#039;&amp;#039;&amp;#039; For efficiency reasons, each module is only imported once per interpreter session. Therefore, if you change your modules, you must restart the interpreter – or, if it’s just one module you want to test interactively, use importlib.reload(), e.g.&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import importlib&lt;br /&gt;
importlib.reload(modulename)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/reference/simple_stmts.html#the-import-statement The import statement] ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import_stmt     ::=  &amp;quot;import&amp;quot; module [&amp;quot;as&amp;quot; identifier] (&amp;quot;,&amp;quot; module [&amp;quot;as&amp;quot; identifier])*&lt;br /&gt;
                     | &amp;quot;from&amp;quot; relative_module &amp;quot;import&amp;quot; identifier [&amp;quot;as&amp;quot; identifier]&lt;br /&gt;
                     (&amp;quot;,&amp;quot; identifier [&amp;quot;as&amp;quot; identifier])*&lt;br /&gt;
                     | &amp;quot;from&amp;quot; relative_module &amp;quot;import&amp;quot; &amp;quot;(&amp;quot; identifier [&amp;quot;as&amp;quot; identifier]&lt;br /&gt;
                     (&amp;quot;,&amp;quot; identifier [&amp;quot;as&amp;quot; identifier])* [&amp;quot;,&amp;quot;] &amp;quot;)&amp;quot;&lt;br /&gt;
                     | &amp;quot;from&amp;quot; relative_module &amp;quot;import&amp;quot; &amp;quot;*&amp;quot;&lt;br /&gt;
module          ::=  (identifier &amp;quot;.&amp;quot;)* identifier&lt;br /&gt;
relative_module ::=  &amp;quot;.&amp;quot;* module | &amp;quot;.&amp;quot;+&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;Python code in one [https://docs.python.org/3/glossary.html#term-module module] gains access to the code in another module by the process of [https://docs.python.org/3/glossary.html#term-importing importing] it.&amp;lt;/blockquote&amp;gt;see [https://docs.python.org/3/reference/import.html The import system] for more details.&lt;br /&gt;
&lt;br /&gt;
== Subdirectories ==&lt;br /&gt;
If a file &amp;#039;&amp;#039;&amp;#039;myfunctions.py&amp;#039;&amp;#039;&amp;#039; with &amp;#039;&amp;#039;&amp;#039;thefunction&amp;#039;&amp;#039;&amp;#039; is places in a subdirectory &amp;#039;&amp;#039;&amp;#039;sub1&amp;#039;&amp;#039;&amp;#039; then we need to write:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from sub1.myfunctions import thefunction&amp;lt;/syntaxhighlight&amp;gt;If a file &amp;#039;&amp;#039;&amp;#039;myfunctions.py&amp;#039;&amp;#039;&amp;#039; with &amp;#039;&amp;#039;&amp;#039;thefunction&amp;#039;&amp;#039;&amp;#039; is places in a subdirectory &amp;#039;&amp;#039;&amp;#039;sub1/sub2&amp;#039;&amp;#039;&amp;#039; (&amp;#039;&amp;#039;&amp;#039;sub1\sub2&amp;#039;&amp;#039;&amp;#039; depending on the OS) then we need to write:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from sub1.sub2.myfunctions import thefunction&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [https://docs.python.org/3/tutorial/modules.html#more-on-modules Executing modules as scripts]​ ==&lt;br /&gt;
When you run a Python module with&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;python fibo.py &amp;lt;arguments&amp;gt;&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;the code in the module will be executed, just as if you imported it, but with the __name__ set to “__main__”. That means that by adding this code at the end of your module:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    import sys&lt;br /&gt;
    fib(int(sys.argv[1]))&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;you can make the file usable as a script as well as an importable module, because the code that parses the command line only runs if the module is executed as the “main” file:&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;python fibo.py 50​&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;shell&amp;quot;&amp;gt;1 1 2 3 5 8 13 21 34&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;If the module is just imported,&amp;lt;/blockquote&amp;gt;&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;import fibo&amp;lt;/syntaxhighlight&amp;gt;&amp;lt;blockquote&amp;gt;the code is not run.&amp;lt;/blockquote&amp;gt;&lt;/div&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
</feed>