<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Modules_and_Packages</id>
	<title>Modules and Packages - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://training-course-material.com/index.php?action=history&amp;feed=atom&amp;title=Modules_and_Packages"/>
	<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Modules_and_Packages&amp;action=history"/>
	<updated>2026-05-14T01:23:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://training-course-material.com/index.php?title=Modules_and_Packages&amp;diff=9208&amp;oldid=prev</id>
		<title>Kristian Rother: Created page with &quot;{{Cat|Python Commands}} {{Python Links}}  == What is a module? == Any Python file (ending .py) can be imported from another Python script to use it as a library. A single Pyth...&quot;</title>
		<link rel="alternate" type="text/html" href="https://training-course-material.com/index.php?title=Modules_and_Packages&amp;diff=9208&amp;oldid=prev"/>
		<updated>2013-02-05T20:15:09Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Cat|Python Commands}} {{Python Links}}  == What is a module? == Any Python file (ending .py) can be imported from another Python script to use it as a library. A single Pyth...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Cat|Python Commands}}&lt;br /&gt;
{{Python Links}}&lt;br /&gt;
&lt;br /&gt;
== What is a module? ==&lt;br /&gt;
Any Python file (ending .py) can be imported from another Python script to use it as a library. A single Python file is also called a module.&lt;br /&gt;
&lt;br /&gt;
== Importing modules == &lt;br /&gt;
To import from a module, its name (without .py) needs to be given in the import statement. Often, it is helpful to list the variables and functions required explicitly (helps with ebugging).&lt;br /&gt;
Package names may be given as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import fruit&lt;br /&gt;
&lt;br /&gt;
from fruit import fruit_prices&lt;br /&gt;
&lt;br /&gt;
from my_package import fruit&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are the .pyc files for? ==&lt;br /&gt;
When importing, Python generates bytecode files (.pyc) that help to execute programs faster. They are managed automatically, and dont need to be updated.&lt;br /&gt;
&lt;br /&gt;
== Creating packages ==&lt;br /&gt;
For very big programs, it may be useful to divide the Python code into several directories. There are two things to keep in mind when doing that:&lt;br /&gt;
* To import the package from outside, there needs to be a file __init__.py (it may be empty).&lt;br /&gt;
* The directory with the package needs to be in Pythons search path (see below).&lt;br /&gt;
&lt;br /&gt;
== Where Python looks for modules ==&lt;br /&gt;
When importing modules or packages, Python looks in:&lt;br /&gt;
* The current directory.&lt;br /&gt;
* The Python2.6/lib/site-packages folder.&lt;br /&gt;
* Everything in the PYTHONPATH environment variable. In Python, it can be accessed with:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
print sys.path&lt;br /&gt;
sys.path.append(&amp;#039;my_directory&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
import my_package.my_module&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kristian Rother</name></author>
	</entry>
</feed>