<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Make Tech Easier&#187; python</title>
	<atom:link href="http://maketecheasier.com/tag/python/feed" rel="self" type="application/rss+xml" />
	<link>http://maketecheasier.com</link>
	<description>Uncomplicating the complicated, making life easier</description>
	<lastBuildDate>Sun, 12 Feb 2012 15:58:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Easily Create Quicklist For Ubuntu Unity Launcher</title>
		<link>http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06</link>
		<comments>http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06#comments</comments>
		<pubDate>Mon, 06 Jun 2011 23:58:14 +0000</pubDate>
		<dc:creator>Damien</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[launcher]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[quicklist]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[unity]]></category>

		<guid isPermaLink="false">http://maketecheasier.com/?p=34004</guid>
		<description><![CDATA[Previously, we have shown you a list of useful quicklist that you can add to your Ubuntu launcher. While they are useful, creating them is not a one-click affair. You have to copy the .desktop file over to your Home folder, make the amendment and restart Unity. What if there is an easier way to [...]<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06&amp;title=How+to+Easily+Create+Quicklist+For+Ubuntu+Unity+Launcher&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06">How to Easily Create Quicklist For Ubuntu Unity Launcher</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img alt="unity-google-chrome" src="http://imagecdn.maketecheasier.com/2011/05/unity-google-chrome.jpg" title="unity-google-chrome" class="alignleft" width="268" height="219" />Previously, we have shown you a list of <a href="http://maketecheasier.com/8-really-useful-ubuntu-unity-quicklists/2011/05/07">useful quicklist</a> that you can add to your Ubuntu launcher. While they are useful, creating them is not a one-click affair. You have to copy the <em>.desktop</em> file over to your Home folder, make the amendment and restart Unity. What if there is an easier way to create/edit quicklist items for your applications? </p>
<p>Unity Launcher Editor (ULE) is a python script that allows you to edit your Unity launcher. It allows you to add and remove applications to and from the launcher and also create/edit the quicklist items for each application. Compared to the previous way where you have to manually edit the config file, this is definitely a much better way.<br />
<span id="more-34004"></span></p>
<h2>Installation</h2>
<p>Unity Launcher Editor is currently not available in the Ubuntu repository, nor is there a PPA or deb file (as of this post). To install ULE, we have to download the source code from LaunchPad.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> bzr
bzr branch <span style="color: #c20cb9; font-weight: bold;">lp</span>:unity-launcher-editor</pre></div></div>

<p>Once you have downloaded the source code, you should find a &#8220;unity-launcher-editor&#8221; folder in your Home directory. In your Nautilus, navigate to the &#8220;unity-launcher-editor -> unitylaunchereditor&#8221; folder and double-click the <em>main.py</em> file. A prompt will show up:</p>
<p><img src="http://imagecdn.maketecheasier.com/2011/06/ule-run-main-file.png" alt="ule-run-main-file" title="ule-run-main-file" width="537" height="198" class="aligncenter size-full wp-image-34007" /></p>
<p>Click Run. </p>
<p><img src="http://imagecdn.maketecheasier.com/2011/06/ulr-main-gui.png" alt="ulr-main-gui" title="ulr-main-gui" width="600" height="414" class="aligncenter size-full wp-image-34008" /></p>
<h2>Using Unity Launcher Editor</h2>

<p>There are three parts to the ULE. The panel on the left shows the existing applications that are in the launcher. You can select on any app and its details will show up on the right panel. </p>
<p>The top section of the right panel shows the launcher app details while the bottom section shows its quicklist items.</p>
<p>To add quicklist item to an existing application in the launcher, for example Firefox:</p>
<p>1. Select the app (Firefox) icon on the left panel.</p>
<p>2. Under the Quicklist Group, click the + button.</p>
<p><img src="http://imagecdn.maketecheasier.com/2011/06/ule-add-quicklist.png" alt="ule-add-quicklist" title="ule-add-quicklist" width="600" height="408" class="aligncenter size-full wp-image-34009" /></p>
<p>3. Add the quicklist group name and the command you want it to execute. For example, I want to add a Private mode quicklist so I can quickly open a private session in Firefox. </p>
<p><img src="http://imagecdn.maketecheasier.com/2011/06/ulr-new-quicklist-group.png" alt="ulr-new-quicklist-group" title="ulr-new-quicklist-group" width="348" height="212" class="aligncenter size-full wp-image-34011" /></p>
<p>4. Click Save. </p>
<p>Your quicklist item should appear in the launcher. If not, log out and log in again, or restart Unity (<code>unity --replace</code>).</p>
<h2>Adding application to the launcher </h2>
<p>ULE also allows you to add new application to the launcher. This is a two steps process. </p>
<p>1. Click the + button at the bottom of the left panel. Enter the launcher name.</p>
<p><img src="http://imagecdn.maketecheasier.com/2011/06/ule-add-new-app.png" alt="ule-add-new-app" title="ule-add-new-app" width="558" height="296" class="aligncenter size-full wp-image-34012" /></p>
<p>2. Select the newly added launcher. Edit the info at the top section of the right panel. </p>
<p><img src="http://imagecdn.maketecheasier.com/2011/06/ule-new-app-properties.png" alt="ule-new-app-properties" title="ule-new-app-properties" width="600" height="410" class="aligncenter size-full wp-image-34013" /></p>
<p><strong>Note</strong>: Please note that this is not the easiest way to add applications to the launcher. The easiest way is to first run the application that you want to add, then right click its icon on the launcher and select &#8220;Keep in launcher&#8221;.</p>
<p>Do you have an easier way to add quicklist items to the launcher?</p>
<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06&amp;title=How+to+Easily+Create+Quicklist+For+Ubuntu+Unity+Launcher&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06">How to Easily Create Quicklist For Ubuntu Unity Launcher</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maketecheasier.com/easily-create-quicklist-for-ubuntu-unity-launcher/2011/06/06/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Getting Started with Pardus Linux</title>
		<link>http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19</link>
		<comments>http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19#comments</comments>
		<pubDate>Sun, 19 Jul 2009 12:00:00 +0000</pubDate>
		<dc:creator>Joshua Price</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[pardus]]></category>
		<category><![CDATA[pisi]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://maketecheasier.com/?p=5909</guid>
		<description><![CDATA[Pardus is a Linux distribution created and maintained by Scientific &#38; Technological Research Council of Turkey. There&#8217;s certainly no shortage of customized and special-purpose Linux distributions available, but Pardus is unique in several ways. Today, instead of covering the usual aspects of an operating system like installation and included software, I&#8217;m going to cover the [...]<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19&amp;title=Getting+Started+with+Pardus+Linux&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19">Getting Started with Pardus Linux</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-5956" src="http://imagecdn.maketecheasier.com/2009/07/pardus-logo.jpg" alt="pardus-logo" width="150" height="138" /><a href="http://www.pardus.org.tr/eng/index.html" target="_blank">Pardus</a> is a Linux distribution created and maintained by Scientific &amp; Technological Research Council of Turkey.  There&#8217;s certainly no shortage of customized and special-purpose Linux distributions available, but Pardus is unique in several ways.  Today, instead of covering the usual aspects of an operating system like installation and included software, I&#8217;m going to cover the aspects of Pardus that make it so interesting.<br />
<span id="more-5909"></span><br />
One important note before we get too far &#8211; if you decide to install Pardus, <strong>make sure you hit F2 at the first bootup screen to set the language</strong>, unless you want your system in Turkish.</p>
<p>The version tested here is Pardus 2009 RC2</p>
<h3>Kaptan</h3>
<p>The first thing you&#8217;ll see on a new Pardus installation is Kaptan, a desktop config tool.  It allows you to set things like desktop theme, wallpaper, mouse preferences, and menu style.  I found this to be a useful tool for getting everything off on the right foot.  Like all the custom Pardus applications I&#8217;ve seen so far, it&#8217;s oddly beautiful for something so maroon.</p>
<p><img class="aligncenter size-full wp-image-5910" src="http://imagecdn.maketecheasier.com/2009/07/pardus-kaptan.jpg" alt="Initial Kaptan screen" width="577" height="408" /></p>
<p>My only complaint about Kaptan was that at one point it brings you to a config screen for Smolt, without ever telling you what Smolt is or what it&#8217;s supposed to be doing.  Everything else is clear and intuitive.</p>
<h3>PiSi</h3>
<p>One of the things that initially got me interested in Pardus was the the developers seem to share my affinity for the <a href="http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25">Python</a> programming language.  The Pardus developers used Python extensively in building the system, most notably in the package manager PiSi.</p>
<p>PiSi (pronounced pee-see) is the custom-built package manager for Pardus.  it&#8217;s got all the features of a modern package manager, including things like dependency resolution, CLI and GUI interface, search functions and online repositories.  The command line interface provides all the usual options, such as</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pisi search package_name</pre></div></div>

<p>to search for a package and</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pisi <span style="color: #c20cb9; font-weight: bold;">install</span> package_name</pre></div></div>

<p>to install it.</p>
<p>One thing I particularly like about PiSi is the quality output it provides.  If a package fails to install, you get clear output telling you why.  When it does install, you get nicely formatted output (with color!) telling you all about the installation.  Here, for example, is the output I got when I told PiSi to install my favorite video player, VLC.</p>
<p><img class="aligncenter size-full wp-image-5918" src="http://imagecdn.maketecheasier.com/2009/07/pardus-pisi.jpg" alt="An example of PiSi in action" width="576" height="451" /></p>
<p>It&#8217;s a little verbose, but I think quite useful.  Particularly the use of color, which is something I&#8217;ve always liked about Gentoo&#8217;s <em>emerge</em>.  That kind of clear, useful, detailed output is what I wish I could have in all package managers.  Kudos to PiSi for that one!</p>
<p>The only downside I&#8217;ve encountered so far (and it is a big one) is the comparitively small amount of software available in Pardus&#8217;s PiSi repositories.  It&#8217;s got about 2,000 packages, and many of the things I&#8217;ve tried to install have not been available.  It&#8217;s not a huge project, and relatively new in the world of Linux distros, so a lack of packages is somewhat understandable.  Still, having more software available would go a long way toward making Pardus a top-notch distro.</p>
<h3>Package Manager</h3>
<p>After covering PiSi, there&#8217;s not a whole lot to say about Package Manager, which is the graphical front-end to PiSi.  It provides a browsable, searchable interface to the software available to PiSi.  If you&#8217;ve ever used Synaptic, the default package GUI for Ubuntu, you&#8217;ll be right at home in Package Manager.</p>
<p><img class="aligncenter size-full wp-image-5924" src="http://imagecdn.maketecheasier.com/2009/07/pardus-package-manager.jpg" alt="Package Manager" width="577" height="469" /></p>
<h3>Network Manager</h3>
<p>This was one thing that was a bit of a problem for me.  After my initial install, I was surprised to see my network wasn&#8217;t up.  This certainly wasn&#8217;t the first Linux ever run on that machine so there should be no driver issues.  Even trying to bring it up manually at the command line came up with little success.</p>
<p>Then, I ran the Pardus Network Manager tool, and after creating a &#8220;profile&#8221; for my NIC, everything was up and running.  Perhaps it was just the chipset on that machine (a common Intel chipset), but I hope not everyone would have to manually configure a network interface to get basic connection.</p>
<p><img class="aligncenter size-full wp-image-5926" src="http://imagecdn.maketecheasier.com/2009/07/pardus-network.jpg" alt="Network Manager" width="414" height="173" /></p>
<h3>Firewall</h3>
<p>Pardus continues the overall habit of clarity and simplicity with the Firewall utility.  It should be familiar to anyone who&#8217;s used Windows firewalls like ZoneAlarm.</p>
<p><img class="aligncenter size-full wp-image-5927" src="http://imagecdn.maketecheasier.com/2009/07/pardus-firewall.jpg" alt="Firewall configuration" width="539" height="376" /></p>
<p>For some reason I have not yet figured out, the Firewall utility does not seem to recognize my keystrokes.  All other applications take whatever typing I give them, but none of the text boxes in Firewall Manager seem to realize that I&#8217;m typing.</p>
<h3>Conclusion</h3>
<p>Overall I was surprised and impressed by Pardus.  Surprised because it&#8217;s not a name you hear very often in news or conversation, and impressed by the clean, clear, clever design.   To me, the real gem was PiSi.  As a long time <a href="http://maketecheasier.com/become-an-apt-guru/2009/02/24">APT</a> fan I have high expectations in a package manager, and so far PiSi hasn&#8217;t let me down, its even shown me a few things I wish other package managers could do.  Pardus is really slick right now, and I&#8217;m betting it will only get better.</p>
<p>There&#8217;s certainly room for improvement, particularly with the Network and Firewall Managers, but the system itself is beautiful and well designed.  I&#8217;m not quite ready to use Pardus as my main operating system, but in another release or two I think it could give the giants like Ubuntu a real run for their money.</p>
<p><em>For anyone who IS curious about the non-original included software, some notable packages are:</em></p>
<ul>
<li><em>Kernel 2.6.30.1</em></li>
<li><em>KDE 4.2.4</em></li>
<li><em>Firefox 3.5</em></li>
<li><em>OpenOffice 3.1</em></li>
<li><em>Gimp 2.6.6</em></li>
<li><em>Xorg 1.6.2</em></li>
<li><em>Python 2.6.2</em></li>
</ul>
<p><em> </em></p>
<p><!--adsense#468x60--></p>
<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19&amp;title=Getting+Started+with+Pardus+Linux&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19">Getting Started with Pardus Linux</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maketecheasier.com/getting-started-with-pardus-linux/2009/07/19/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>A Basic Introduction To Python 3</title>
		<link>http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25</link>
		<comments>http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25#comments</comments>
		<pubDate>Wed, 25 Mar 2009 00:11:46 +0000</pubDate>
		<dc:creator>Joshua Price</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[py3k]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scripts]]></category>

		<guid isPermaLink="false">http://maketecheasier.com/?p=3485</guid>
		<description><![CDATA[A while back I was introduced to what has become my #1 favorite programming/scripting language: Python. It&#8217;s difficult for a language developer to come up with something that&#8217;s both powerful and easy to write, something that flows naturally and allows you to focus on what&#8217;s important in your code. Python does this beautifully. It makes [...]<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25&amp;title=A+Basic+Introduction+To+Python+3&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25">A Basic Introduction To Python 3</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-3486" src="http://imagecdn.maketecheasier.com/2009/03/280px-python_logo-150x150.png" alt="Python Logo" width="150" height="150" />A while back I was introduced to what has become my #1 favorite programming/scripting language: Python.  It&#8217;s difficult for a language developer to come up with something that&#8217;s both powerful and easy to write, something that flows naturally and allows you to focus on what&#8217;s important in your code.  Python does this beautifully.  It makes just the right kinds of assumptions, allowing you to focus more on what your program should do instead of exactly how it should be done.  There&#8217;s no worrying about memory management, variable typing, or those blasted semicolons, you just keep your mind on the logic of your application.</p>
<p><span id="more-3485"></span>Python takes some pretty big departures from some of the more traditional languages like C/C++, fitting in better with the dynamic languages like Ruby, Smalltalk, and even Javascript.  The ability to quickly and easily finish complex tasks in Python has even been the subject of some great <a href="http://xkcd.com/353/" target="_blank">web</a> <a href="http://xkcd.com/413/" target="_blank">comics</a>.</p>
<blockquote><p>Note &#8211; Python is an interpreted language, the interpreter can be downloaded <a href="http://python.org" target="_blank">here</a>. All examples in this guide are written for Python 3.0 which is <strong>NOT</strong> fully backward-compatible with prior versions. If you&#8217;re having trouble running the examples, check your Python version.</p></blockquote>
<h3>Running the examples</h3>
<p>I&#8217;ll include various examples throughout this guide.  Once you&#8217;ve got the Python 3 interpreter installed (make sure it&#8217;s Python 3), code can be run in two ways:</p>
<h3>Script file</h3>
<p>You can copy/paste the complete text of the example code into a text file.  Python files typically end in .py.  Open your command prompt and run the Python executable followed by the name of the file.  On my Linux machine, I run:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">python3.0 myfile.<span style="color: black;">py</span></pre></div></div>

<p>This should be roughly the same on Windows and Mac as well, though you may have to specify the full path to the Python interpreter, such as</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">C:\Python30\python.<span style="color: black;">exe</span> myfile.<span style="color: black;">py</span></pre></div></div>

<h3>Interactive Interpreter</h3>
<p>Python can also be run in interactive mode, where you can type in commands one at a time to see how it responds.  This can be very useful in troubleshooting, or in trying out new things.  Run the Python executable on its own, without any script file, and it will open up the interactive prompt.</p>
<p><img class="aligncenter size-full wp-image-3735" src="http://imagecdn.maketecheasier.com/2009/03/interpreter.png" alt="Python interactive interpreter" width="515" height="278" /></p>
<p>Ctrl-D will exit the interpreter.</p>
<h3>Whitespace</h3>
<p>One of the most unusual aspects of Python is its use of whitespace to indicate blocks of code. Instead of <em>begin</em> and <em>end</em>, or grouping by brackets, Python uses the amount of indentation to tell how to handle blocks of code for looping and such. To many people coming from other programming languages, this seems like insanity. Once you get used to the idea, however, it becomes quite natural and forces your code to be clear and readable. We all indent code blocks anyway (or at least should) so it just makes sense for the language to understand that statements all lined up together are part of the same block.</p>
<p>As an added benefit, Python is not picky about just how much you like to indent, or even whether you prefer tabs or spaces. You can use a tab, a space, two spaces, 137 spaces, Python doesn&#8217;t care. All you need to do is be consistent. It will check your code and see &#8220;The first code block is indented by 4 spaces, so I&#8217;ll assume each other block is indented by another 4 spaces&#8221; or whatever the case may be. As long as you&#8217;re consistent in the way you indent your code, Python is flexible enough to understand. The following example may help clear things up.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">x = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">while</span> x <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">10</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span>
    x += <span style="color: #ff4500;">1</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;All done&quot;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Code Breakdown: </strong>The <em>while</em> loop tells Python to run the following block of code as long as certain conditions are true. In this case, the condition is that x is less than 10. It will continue to loop over that block until x hits 10. The &#8220;x += 1&#8243; translates to &#8220;x = x + 1&#8243; or &#8220;make x larger by 1&#8243;. Notice the final line does not get run until the <em>while</em> loop is finished. Python sees the indented lines, and treats those as the group of code to be run on each trip through the <em>while</em> loop. The final line is not indented with the others, so Python does not act on it until the <em>while</em> loop is finished.</p>
<h3>Dynamic Typing</h3>
<p>Python does not require you to define what type of data will be in a variable.  You can put an integer, a string, a decimal, anything you want into a variable without having to tell Python what it is.  Python will figure out, based on what you assign, what type of data that variable should hold.  The following example should demonstrate:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">x = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;x is a: &quot;</span>,<span style="color: #008000;">type</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
x = <span style="color: #ff4500;">3.14</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;x is a: &quot;</span>,<span style="color: #008000;">type</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
x = <span style="color: #483d8b;">&quot;Hello&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;x is a: &quot;</span>,<span style="color: #008000;">type</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
x = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;x is a: &quot;</span>,<span style="color: #008000;">type</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>Which gives us the output below</p>
<p><img class="aligncenter size-full wp-image-3643" src="http://imagecdn.maketecheasier.com/2009/03/type-example.png" alt="Example of Python's dynamic typing" width="236" height="141" /></p>
<h3>Data Structures</h3>
<p>The three data structures you&#8217;ll most commonly use in python are</p>
<ul>
<li>Lists</li>
<li>Tuples</li>
<li>Dictionaries</li>
</ul>
<h3>Lists</h3>
<p>are a lot like arrays in some other languages.  They&#8217;re a one-dimensional sequence of items (though technically you can give them as many dimensions as you like).  Each item in that list can be changed, moved, and removed at will without having to recreate the list, and without causing any change to the other items.  Lists can contain any Python object, whether it be a number, a string, even other lists.  The following code shows some basic usage of lists.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#create a list with a few sample items</span>
myList = <span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span>,<span style="color: #ff4500;">2</span>,<span style="color: #ff4500;">3</span>,<span style="color: #ff4500;">4</span>,<span style="color: #ff4500;">5</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#len() gives a count of how many items our list holds</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;myList has &quot;</span>, <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>myList<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot; items.&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#The items in a list don't have to be of the same type</span>
myList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;six&quot;</span><span style="color: black;">&#41;</span>
myList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;seven&quot;</span><span style="color: black;">&#41;</span>
myList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#We've appended three new items to the end of the list</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;myList now has&quot;</span>,<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>myList<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot; items.&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Now let's see item number 0 (first item)</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;first item:&quot;</span>, myList<span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#and now the fourth item</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;fourth item:&quot;</span>,mylist<span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Then pop the last item out of the list</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;and ends with&quot;</span> , myList.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;myList now has&quot;</span>,<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>myList<span style="color: black;">&#41;</span>, <span style="color: #483d8b;">&quot; items.&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#And see what we've done</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;The complete contents are:&quot;</span>, myList<span style="color: black;">&#41;</span></pre></td></tr></table></div>

<h3>Tuples</h3>
<p>I won&#8217;t be covering tuples much, as they won&#8217;t be used it our example program and they&#8217;re similar to lists in many ways.  Tuples, like lists, are a series of items grouped together.  The difference is that tuples are not mutable.  You cannot make in-place changes to the items in a tuple, you must re-create the tuple.  This means no &#8220;append&#8221; or &#8220;pop&#8221; or other things that directly make changes to the contents of the tuple.  If it helps, you can think of tuples as a read-only list (though that&#8217;s really not very accurate).</p>
<h3>Dictionaries</h3>
<p>These, I love.  When I was first taught about dictionaries, I remember thinking something along the lines of &#8220;Well.. I GUESS that could be useful&#8230; sometimes&#8221;.  Within a week, I used them every chance I got.</p>
<p>In Python, dictionaries are key:value pairs.  It&#8217;s kinda like a list except that each item has two parts, a key and a value.  In the following example, I&#8217;m going to make a dictionary to hold information about myself.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="python" style="font-family:monospace;">myDict = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#       Key             Value</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Name&quot;</span><span style="color: black;">&#93;</span>       = <span style="color: #483d8b;">&quot;Josh&quot;</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Occupation&quot;</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">&quot;Computer Geek&quot;</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FavFood&quot;</span><span style="color: black;">&#93;</span>    = <span style="color: #483d8b;">&quot;Hani Special (no lettuce)&quot;</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FavBand&quot;</span><span style="color: black;">&#93;</span>    = <span style="color: #483d8b;">&quot;Anything but the B-52s&quot;</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Heroes&quot;</span><span style="color: black;">&#93;</span>     = <span style="color: #483d8b;">&quot;Tom Waits, Kurt Vonnegut, SpaceBat&quot;</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FavNumber&quot;</span><span style="color: black;">&#93;</span>  = <span style="color: #ff4500;">3.141592</span>
myDict<span style="color: black;">&#91;</span><span style="color: #ff4500;">42</span><span style="color: black;">&#93;</span>           = <span style="color: #483d8b;">&quot;It's also a good number&quot;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;My name:&quot;</span>,            myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Name&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;My heroes:&quot;</span>,          myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Heroes&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;My favorite number:&quot;</span>, myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FavNumber&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;What do I think of 42?&quot;</span>, myDict<span style="color: black;">&#91;</span><span style="color: #ff4500;">42</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;"># Now I'll change my favorite number without creating a</span>
<span style="color: #808080; font-style: italic;"># whole new dictionary</span>
myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FavNumber&quot;</span><span style="color: black;">&#93;</span> += <span style="color: #ff4500;">100</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;My NEW favorite number:&quot;</span>,myDict<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;FavNumber&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>A few things should be clear from the example.  First, dictionaries can mix and match data of any type.  Your keys and values can be of anything.  You can even get really crazy and put things like functions inside dictionaries, but that&#8217;s way beyond the scope of this guide.</p>
<p>Second, dictionaries are mutable.  You can add and remove items on the fly without recreating the dictionary or affecting other items.</p>
<p>If you&#8217;re still not sure of the usefulness of dictionaries, consider using them to track a user&#8217;s settings.  You could have a dictionary called <em>settings</em> and store things like username, ip address, and screen resolution.  Any time you need to reference that data, you can just pull it from <em>settings["username"]</em>, or whatever other key you&#8217;ve specified.</p>
<h3>Bring it all home</h3>
<p>Now we&#8217;re going to get to the real action, creating a useful Python 3.0 program.  What this program will do is take a number representing money, and tell you how much pocket change would make that amount.  It&#8217;s a pretty common coding exercise and is a good way to demonstrate the concepts we&#8217;ve covered so far.</p>
<p>I should tell you now that this program is NOT going to be written in the &#8220;best&#8221; way, my aim is to write it using the most basic concepts and operations possible.  There are several &#8220;better&#8221; ways to write this, such using functions and the modulus operator, and including error checking, but this version should be pretty easy to understand.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#Get the cash amount</span>
total = <span style="color: #008000;">input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Enter cash amount in dollars:  $&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Reading from text input assumes text, so convert</span>
<span style="color: #808080; font-style: italic;">#to decimal and multiple by 100 so we can count pennies</span>
<span style="color: #808080; font-style: italic;">#(simpler math that way)</span>
pennies = <span style="color: #008000;">float</span><span style="color: black;">&#40;</span>total<span style="color: black;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">100</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#create dictionary to hold our change values</span>
change = <span style="color: black;">&#123;</span><span style="color: #483d8b;">&quot;quarters&quot;</span> : <span style="color: #ff4500;">0</span>,
          <span style="color: #483d8b;">&quot;dimes&quot;</span>    : <span style="color: #ff4500;">0</span>,
          <span style="color: #483d8b;">&quot;nickels&quot;</span>  : <span style="color: #ff4500;">0</span>,
          <span style="color: #483d8b;">&quot;pennies&quot;</span>  : <span style="color: #ff4500;">0</span><span style="color: black;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Loop until all money has been accounted for</span>
<span style="color: #ff7700;font-weight:bold;">while</span> pennies <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
  <span style="color: #808080; font-style: italic;">#Subtract each coin from the total, add 1 to count</span>
  <span style="color: #808080; font-style: italic;">#for each coin, and restart loop after counting</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> pennies <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">25</span>:
    change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;quarters&quot;</span><span style="color: black;">&#93;</span> += <span style="color: #ff4500;">1</span>
    pennies -= <span style="color: #ff4500;">25</span>
    <span style="color: #ff7700;font-weight:bold;">continue</span>
  <span style="color: #ff7700;font-weight:bold;">elif</span> pennies <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">10</span>:
    change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;dimes&quot;</span><span style="color: black;">&#93;</span> += <span style="color: #ff4500;">1</span>
    pennies -= <span style="color: #ff4500;">10</span>
    <span style="color: #ff7700;font-weight:bold;">continue</span>
  <span style="color: #ff7700;font-weight:bold;">elif</span> pennies <span style="color: #66cc66;">&gt;</span>= <span style="color: #ff4500;">5</span>:
    change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;nickels&quot;</span><span style="color: black;">&#93;</span> += <span style="color: #ff4500;">1</span>
    pennies -= <span style="color: #ff4500;">5</span>
    <span style="color: #ff7700;font-weight:bold;">continue</span>
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pennies&quot;</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>pennies<span style="color: black;">&#41;</span>
    pennies = <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #808080; font-style: italic;">#Finally, print our results</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Q:&quot;</span>,change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;quarters&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;D:&quot;</span>,change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;dimes&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;N:&quot;</span>,change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;nickels&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;P:&quot;</span>,change<span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;pennies&quot;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p><strong>Code Breakdown:</strong> We&#8217;re using <em>input</em> to get an amount of money in from the command line.  Python assumes that what is being entered is a string of text, as opposed to a number, so we&#8217;ve got to tell it to convert that input into a usable number.  We could have left the number alone (ie 15.95) but instead we converted it to pennies (multiplying by 100) to make the maths simpler so we wouldn&#8217;t have to worry about decimal points.</p>
<p>Next, we create a dictionary to hold the results of our computing.  If this were a more complex program, we could pass that dictionary around to our functions, classes, etc without worrying about keeping track of separate variables for each type of coin.</p>
<p>After that comes the real work &#8211; the act of splitting our money total into individual coins.  This program uses a <em>while</em> loop to keep cycling until we have no money left from our original input.  Each trip through the loop looks at the amount of money, subtracts the largest coin it can, and restarts the loop.  Instead of doing subtractions over and over, this program would likely be much more efficient if we had used the modulus operator, but the subtraction is easier to understand.</p>
<p>Once we&#8217;re finished with the loop, all that&#8217;s left to do is display our results.</p>
<p>Python is capable of FAR more than I could possibly cover here, but I hope I&#8217;ve been able to demonstrate the basics of how it works, and how it can be used to quickly and easily create tools that would be much more complicated in a less intuitive language.</p>
<blockquote><p>In case anyone is as curious as I was about how to properly pronounce &#8220;tuple&#8221;, I was fortunate enough to have the opportunity to ask <a href="http://www.python.org/~guido/" target="_blank">Guido van Rossum</a> himself if it was &#8220;toople&#8221; or &#8220;tupple&#8221;, and he gave the somewhat unsatisfying answer &#8220;It&#8217;s whatever you want.&#8221;</p></blockquote>
<p><!--adsense#468x60--></p>
<p><div style="float:left;margin-bottom:10px"><a href="http://api.tweetmeme.com/share?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25&amp;service=bit.ly" target="_blank"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" style="border:none;margin-right:5px" width="51" height="61"></a><a href="http://digg.com/tools/diggthis/login?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" target="_blank"><img src="http://images.maketecheasier.com/diggme.png" style="border:none;margin-right:5px" ></a><a href="http://www.facebook.com/sharer.php?u=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" target="_blank"><img src="http://images.maketecheasier.com/fb.jpg" style="border:none;margin-right:5px" ></a><a href="http://www.google.com/reader/link?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25&amp;title=A+Basic+Introduction+To+Python+3&amp;srcTitle=MakeTechEasier.com" target="_blank"><img src="http://images.maketecheasier.com/gbuzz-feed.png" style="border:none;margin-right:5px" ></a><a href="http://www.stumbleupon.com/submit?url=http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25" target="_blank"><img src="http://images.maketecheasier.com/stumble.png"></a></div>
<div style="clear:both"></div>
<strong><a href="http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25">A Basic Introduction To Python 3</a></strong> originally published on <a href="http://maketecheasier.com">Make Tech Easier</a> (<a href="http://feedproxy.google.com/MakeTechEasier">RSS</a>)
<br/>
Follow us at <a href="http://www.facebook.com/MakeTechEasier">Facebook</a> | <a href="http://twitter.com/MakeTechEasier">Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maketecheasier.com/a-basic-introduction-to-python-3/2009/03/25/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

