<?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>The Maemo &#187; Nokia N900</title>
	<atom:link href="http://www.themaemo.com/category/devices/n900-devices/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.themaemo.com</link>
	<description>Maemo News , Hacks , Themes , Wallpapers and More</description>
	<lastBuildDate>Tue, 25 May 2010 10:36:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>HowTo: Install Ovi Store apps from the command line on the N900</title>
		<link>http://www.themaemo.com/howto-install-ovi-store-apps-from-the-command-line-on-the-n900/</link>
		<comments>http://www.themaemo.com/howto-install-ovi-store-apps-from-the-command-line-on-the-n900/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 08:53:35 +0000</pubDate>
		<dc:creator>archebyte</dc:creator>
				<category><![CDATA[Applications - Apps]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Hacks ,Tricks and Tips]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[maemo5]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[xterm]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=420</guid>
		<description><![CDATA[
Disclaimer: If you are not comfortable with the command line, do not try this.
If you have installed an app from the Ovi Store web portal, you would have noticed that the process is not fast. Clicking the Download link opens the Application-Manager which takes anywhere from 30-40 seconds to prepare the system before actually starting [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-install-ovi-store-apps-from-the-command-line-on-the-n900%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-install-ovi-store-apps-from-the-command-line-on-the-n900%2F" height="61" width="51" /></a></div>
<p><em>Disclaimer: If you are not comfortable with the command line, do not try this.</em></p>
<p>If you have installed an app from the Ovi Store web portal, you would have noticed that the process is not fast. Clicking the Download link opens the Application-Manager which takes anywhere from 30-40 seconds to prepare the system before actually starting the download. For those who don&#8217;t like to wait, the apt-get command is a great alternative to speed up things and also allow installing multiple apps (at least the ones that are free) in one go.</p>
<h2>Prerequisites</h2>
<p>There are two things required before starting the download. Setting up the Ovi Repo and creating an Archive folder. You need to do this only once.</p>
<h3>Ovi Repo</h3>
<p>If you have never used the Ovi Store, you would need to have the repo installed first. Downloading an app from the store automatically adds the repo the first time but you need an Ovi account. So if you want the apps but don&#8217;t like signing in, you can add the repo manually:<br />
Name: Ovi<br />
Web: https://downloads.maemo.nokia.com/fremantle/ovi/<br />
Dist: ./</p>
<h3>Archive Folder:</h3>
<p>In order to save space on the root partition, create a download directory for the downloaded packages. Instructions <a href="http://wiki.maemo.org/Keep_a_safe_copy_of_your_favorite_applications#Create_the_Archive_folder">here</a></p>
<h2>Installation</h2>
<p>For installation, all you need is the application&#8217;s package name. The apt-cache command can be used to find it. The following command will search and list all packages with the word &#8216;offscr&#8217; in it:</p>
<pre># apt-cache search offscr</pre>
<p>This will display the 31 nifty apps by Offscr currently available. This also searches descriptions.</p>
<p>Next, install the desired package using apt-get (as root of course):</p>
<pre># apt-get -o dir::cache=/home/user/MyDocs/apt-archive-cache install  offscr-discs  offscr-backgammon  offscr-watch</pre>
<p>This will start the installation process for all 3 apps which will take about the same time it takes for one install from the website. Enjoy!</p>
<p><a href="http://www.directphoneshop.co.uk/coming-soon-mobile-phones.asp">Latest Mobile Phones 2010</a><img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=420&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/howto-install-ovi-store-apps-from-the-command-line-on-the-n900/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Nokia N900 Major Firmware PR 1.1 out!</title>
		<link>http://www.themaemo.com/nokia-n900-major-firmware-pr-1-1-out/</link>
		<comments>http://www.themaemo.com/nokia-n900-major-firmware-pr-1-1-out/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 06:21:10 +0000</pubDate>
		<dc:creator>Siraj</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[maemo 5]]></category>
		<category><![CDATA[maemo browser]]></category>
		<category><![CDATA[Maemo firmware]]></category>
		<category><![CDATA[Maemo major update]]></category>
		<category><![CDATA[maemo pr1.1]]></category>
		<category><![CDATA[maemo ram limit]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[n900 fm transmitter demo]]></category>
		<category><![CDATA[n900 ovistore]]></category>
		<category><![CDATA[n900 speakers]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=408</guid>
		<description><![CDATA[Nokia N900 Major Firmware PR 1.1 out!

 
Hi folks a major firmware update for Nokia N900 is out. The Update is called PR  1.1 Release1.2009.42.11 to PR1.1 release 2.2009.51. Maemo 5 PR1.1 is being released on January 14, 2010. Starting in Finland at 7am local time and following a staggering process country by country through [...]]]></description>
			<content:encoded><![CDATA[<a href='http://www.themaemo.com/nokia-n900-major-firmware-pr-1-1-out/' class='retweet vert' >Nokia N900 Major Firmware PR 1.1 out!</a><div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fnokia-n900-major-firmware-pr-1-1-out%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fnokia-n900-major-firmware-pr-1-1-out%2F" height="61" width="51" /></a></div>
<p><img src="http://www.fonearena.com/blog/wp-content/uploads/2010/01/nokia-n900-v51.1-firmware-summary.png" alt="" /><br />
<span style="color: #000000;"><span style="font-family: 'trebuchet ms',arial,helvetica,sans-serif; font-size: 12px; text-align: left;"> </span></span></p>
<p style="margin: 0px; padding: 10px 0px; font-size: 9pt;">Hi folks a major firmware update for Nokia N900 is out. The Update is called PR  1.1 Release<strong style="margin: 0px; padding: 0px; font-size: 13px;">1.2009.42.11 to PR1.1 release 2.2009.51. Maemo 5 PR1.1 is being released on January 14, 2010. Starting in Finland at 7am local time and following a staggering process country by country through the different time zones.</strong></p>
<p style="margin: 0px; padding: 10px 0px; font-size: 9pt;">This update can be installed over the air by users with the PR1.0.1 already installed. Images for flashing will be available later today as well.</p>
<p style="margin: 0px; padding: 10px 0px; font-size: 9pt;">The Maemo 5 SDK and tools are being updated as well in order to match the OS content. The update will be available later today.</p>
<p style="margin: 0px; padding: 10px 0px; font-size: 9pt;"><span style="margin: 0px; padding: 0px;"><strong style="margin: 0px; padding: 0px; font-size: 13px;"><span style="margin: 0px; padding: 0px;">Tons of Changelogs after the brea</span></strong></span><strong style="margin: 0px; padding: 0px; font-size: 13px;"><span style="margin: 0px; padding: 0px;">k!</span></strong></p>
<p style="margin: 0px; padding: 10px 0px; font-size: 9pt;"><strong style="margin: 0px; padding: 0px; font-size: 13px;"><span style="margin: 0px; padding: 0px;"><span id="more-100" style="margin: 0px; padding: 0px;"> </span><span id="more-408"></span><br style="margin: 0px; padding: 0px;" /></span></strong></p>
<h2 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">New features</span></h2>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Hutchison SIM cards are supported.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">MS Exchange 2003 support.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Maemo Update</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Bootloader (Nolo) can be updated over Maemo Update.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Cellular software can be updated over Maemo Update.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Icon cache removed to allow more memory space for Maemo Update.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Application Manager: Available space check moved to apt-worker for more accurate results.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Reliability</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Improvements in SGX performance and reliability.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Use-time and power consumption</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">API for status area applets to detect if they are invisible/absent.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Fixes to Pulseaudio timer increasing power saving when starting/closing apps.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Browser: Removed unnecessary serial logging.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Reduction of wake-ups in Desktop, Connectivity, Conversations, RSS Feed Reader,</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Backup handles correctly directories containing pairs of symlinks.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Less CPU load caused during video recording.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Support disabling Virtual Keyboard in input field.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Performance improvements in Browser.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Lock: “swipe to unlock” will not stay on.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">CPU idle latencies and thresholds updated.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Fixing eMMC data lines while sleeping.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">CellMO power consumption reduced.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Usability</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Volume button operation in call flipped based on audio routing (no more on screen orientation).</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Browser: Downloading &amp; rendering of page content runs promptly.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Helping to avoid capacity limits of rootfs when installing apps (make Docpurge aware of /opt).</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Stability and usability fixes to the Profiles applet. Selection, usage and restoring of ringtones.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Fast call from home shortcuts.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Fast SMS rejection of incoming call.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Avoid false alarms in pocket.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Silence ringing by flipping face down.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Fix to Camera photo orientation problem: correct orientation is now written to EXIF.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Performance</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">X: performance of GLES apps improved.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Lower RAM consumption while capturing video.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Phone-UI &amp; Msg-UI always ready to appear.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Application Manager UI speed improvements.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Email faster with large mailboxes.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Large file copy (SD-&gt;MMC) doesn’t degrade system performance.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">OVI Maps</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Route calculation and search performance improved.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Connectivity</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">BT Secure Simple Pairing fixed for Windows Vista.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">BT transfer progress indicated.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Improving WLAN connection stability.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Improved WLAN negotiation when going out of reach of access point.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Phonecalls</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Add voicemail shortcut support.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Showing call forwarding correctly when busy forwarding is not set.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Call log improved.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Audio &amp; Video</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Audio volume control works with +/- keys in full-screen playback of flash.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Handling corrupted ring tone files better.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">HW volume keys always have same orientation.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Media Player UI now provides feedback when tapping control buttons in video playback.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">MIC input not clipped when loud voice in VoIP call.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Pulseaudio: Ringtone is heard from the loudspeaker if BT connected.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Ringtone played both to headset (BT or wired) and to internal HF speakers.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">AV sync fix for recorded videos.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Camera</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">ISO EXIF value for images saved when automatic sensitivity in use.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Vignetting test of 2nd camera fixed, VGA sensor stability.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Battery and Charging</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Improved charging in case of low charging power (PC USB charging).</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">USB</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Fixing the USB detection and card mounting issue related to quickly attaching/detaching the cable.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Able to format corrupted eMMC properly.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Hang fixed in case of WLAN disconnection while copying files.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Synchronization</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Activesync supports now MS Exchange 2003.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Activesync – fixes the forwarding of attachments showing incorrect sizes (Exchange server 2003).</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Content copier of PC Suite enabled. Whole content backup (including Notes) can now be restored from PCSuite.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">3rd party applications</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Policy-settings: Fixes rotation transition in for 3rd party applications.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Policy-settings: By default, 3rd party apps should have the same limits as our applications.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Calendar</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Public API for color picker. Home widget is now translucent.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Set/get alarms API.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Syncing of task alarms supported.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Image Viewer</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Thumbnailing faster.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Application Manager</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Rename Maemo Extras to maemo.org and enable by default.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">Grid view applied for the categories in download view. Added API for filtering packages.</span></li>
</ul>
<h3 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Development Platform</span></h3>
<ul style="margin: 0px; padding: 0px 0px 0px 30px;">
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">SDK content and tools updated.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">SDK GUI installer updated.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">New sharing-dialog-dev package added to enable Bluetooth and email sending.</span></li>
<li style="margin: 0px; padding: 0px;"><span style="color: #000080;">New wappushd-dev package documenting MMS interfaces available.</span></li>
</ul>
<h2 style="margin: 0px; padding: 10px 0px; font-family: Verdana;"><span style="color: #000080;">Community reports fixed</span></h2>
<p><span style="color: #333333; font-family: 'Lucida Grande',Arial,Helvetica,sans-serif; font-size: 12px; line-height: 18px;"> </span><br />
Browser</p>
<p>* &#8220;&#8221;About Flash Player&#8221;" contextual menu item treated as unrequested pop-up<br />
* Focus not set to location bar after Ctrl-L shortcut is used<br />
* Spacebar scrolls more than 1 page<br />
* microb doesn&#8217;t trigger onchange<br />
* Page is not rerendered when JavaScript actions increase page length<br />
* Complete Browsing History on the N900 sometimes displays &#8220;&#8221;None&#8221;"<br />
* The menu item &#8220;&#8221;copy&#8221;" in the browser menu does not work<br />
* OK button remains disabled in dialog for Integer settings in about:config<br />
* Browser window checkerboards and repaints when navigated to from multi-task view<br />
* Sometimes the browser window goes black for over a second after clicking the fullscreen/restore button</p>
<p>Calendar</p>
<p>* Start and end times are changing when daylight saving time ends (begins)<br />
* Incorrect entries in the Birthday Smart Calendar<br />
* Changing to next week is very slow<br />
* Smart birthday-widget doesn&#8217;t show up any birthdays or shows one on random</p>
<p>Chat &amp; Call &amp; SMS</p>
<p>* Phone app crashed as call ending<br />
* Dialer does not accept SS (3GPP TS 22.030) dial strings<br />
* Unclear how to open a contact (sender/receiver) of a conversation<br />
* High latency between UI and SIP events being sent<br />
* clicking on notification window fails for 2 or more messages when in Dashboard<br />
* Skype does not allow entering DTMF tones<br />
* skype: Call does not support DTMF tones<br />
* Can&#8217;t send sms/chat to known contact from the Call list<br />
* libnice violates Debian packaging policy for description of package &#8220;&#8221;libnice0&#8243;&#8221;<br />
* Volume buttons should be swapped when using the phone in portrait mode.<br />
* Call Log only displays contact name that called, not phone number<br />
* Show wrong Contact for a SMS after a couple of days<br />
* scrollbar instead of kinetic scrolling<br />
* Chat window for jabber / xmpp is not always updated with new incoming messages</p>
<p>Connectivity</p>
<p>* Bluetooth DBUS UI dialogs &#8211; wrong args in the example code<br />
* Button style in Bluetooth file receive applet is wrong<br />
* Inconsistent keyboard behaviour when configuring a static ip address<br />
* Drops WLAN connection to Linksys WRT610N after 10-15 minutes<br />
* after failed pairing to bluetooth car kit bluetooth can&#8217;t be turned on<br />
* Wrong settings for Orange (France) gprs<br />
* udhcpc overriding default routes</p>
<p>Contacts</p>
<p>* address book cannot import vcards from benq/siemens phones properly<br />
* Contacts re-appear in list after disableing and re-enableing accounts<br />
* No hint that it is impossible to paste an strings containing non-numeric characters into a phone number field<br />
* Skype Support&gt;Report problem leads to an error page</p>
<p>Core</p>
<p>* N900 sometimes ignores USB data cable</p>
<p>Desktop platform</p>
<p>* Publish sources of alarm framework<br />
* Failed to build libosso-2.19 from Fremantle repo (ggc 4.3.2)<br />
* wdgt_va_full_12h_time, wdgt_va_12h_hours should be replaced by wdgt_va_full_12h_time_am/wdgt_va_full_12h_time_pm and wdgt_va_12h_hours_am/wdgt_va_12h_hours_pm<br />
* Easy to enter ~ ^ &#8216; ` &#8220;&#8221; symbols with 3rd row of special character view<br />
* &#8220;&#8221;More&#8230;&#8221;" applications launcher does&#8217;t allow scrolling<br />
* Can&#8217;t easily align desktop widgets (snap to position) on home screens<br />
* Allow keyboard input to jump to an entry in a list (&#8220;&#8221;type ahead&#8221;")<br />
* No rubber-banding effect in the Main &#8220;&#8221;More&#8230;&#8221;" menu (task launcher)<br />
* WiFi password shows up in auto-completion<br />
* When applying a different theme, not all colors change in application manager<br />
* libsdl: Task switcher area can be a dead area<br />
* FN-lock and Ctrl+Backspace breaks input for used application<br />
* Application Manager moves to background after start when quickly clicking<br />
* Typing in newly opened window brings up contact search<br />
* Race condition with hardware shift key<br />
* Home view blurs on triple-tapping the launcher grid icon<br />
* Hanging application menu requires system reboot<br />
* Rotation in 42-11 is not as smooth as in 41-10 for some third party apps<br />
* &#8220;&#8221;More&#8230;&#8221;" view is not sorted at all<br />
* Add a (short shown) scroll bar in the status area window to indicate that there are more elements inside as actually shown<br />
* Updating software removes desktop shortcuts</p>
<p>Desktop Widgets</p>
<p>* AP News Widget causes Excessive CPU wakeups<br />
* Contact widgets move to active desktop after merge<br />
* Media Player widget suddenly starts music after Phone call ends</p>
<p>Development Platform</p>
<p>* Link to C code not working (not a link in fact) on Fremantle camera api dev page<br />
* Package downloads should be retried when the http connection time-outs<br />
* Link for osso_wlan documentation broken<br />
* Video indexing failed in SDK (Tracker issue?)<br />
* xkbdata: Inconsistency between installed packages in SDK and FW<br />
* example source code not available in &#8220;Writing a new maemo application&#8221;<br />
* e2fsprogs derivative packages not available?<br />
* HildonTouchSelector example has wrong parameters in callback function<br />
* URL for sharing plugin template missing</p>
<p>Email</p>
<p>* Does not always mark e-mails as read (dovecot/cyrus/google IMAP server)<br />
* Modest reports email username / password incorrect when it is correct<br />
* Performance is unusable on IMAP accounts with a large number of messages in one or more folders (e.g. INBOX)<br />
* When an IMAP account is selected, only refresh that account&#8217;s folders<br />
* Locales not working correctly<br />
* Deleting email should be more evident&#8230;<br />
* Fix modest compilation warning<br />
* Remove HildonDialog deprecated symbol<br />
* Import conic support only if It&#8217;s available<br />
* Remove Hildon 0.x conditional code<br />
* Remove Hildon 1.x conditional code in Hildon2 version of modest<br />
* Modest doesn&#8217;t take care of preferences for automatic update<br />
* New email notification leads to blank email instead of email itself<br />
* Double-tapping &#8220;&#8221;Inbox&#8221;" sometimes opens &#8216;empty&#8217; Inbox<br />
* nokia messaging doesn&#8217;t synchronize selected imap folders<br />
* Long delays when opening emails &#8211; viewer window shows &#8220;&#8221;Updating&#8221;"</p>
<p>Images and Camera</p>
<p>* When ISO sensitivity is set to automatic, ISO EXIF value in resulting image is 0<br />
* Vertical photos from other devices should fill more space when shown in portrait.<br />
* User-facing camera produces a left side dark vertical band<br />
* Audio does not sync with video (and is ultimately unsyncable)<br />
* Improve zooming</p>
<p>Location</p>
<p>* Bluetooth GPS reconnect dialog refuses to go away after clicking &#8220;&#8221;No&#8221;"</p>
<p>Map</p>
<p>* USA localization displays distance in kilometers<br />
* Can&#8217;t delete route waypoints in Map application<br />
* Route Settings screen is not finger friendly</p>
<p>Media player</p>
<p>* Information on artist / track not updated in media player with internet radio<br />
* Plays next radio station when current station cuts out / has playback issues<br />
* flashing pixels around the lock button if media player is playing a video.<br />
* Media player track search only matches the beginning of title/artist<br />
* Viewing songs by &#8220;&#8221;Artists&#8221;" automatically scrolls to the end of the list</p>
<p>Multimedia</p>
<p>* N900 needs to be rebooted if media player fails to play video (h264dec)<br />
* Volume in media player jumps when receiving emails, IMÂ´s or smsÂ´s<br />
* Can&#8217;t change FM TX radio station name<br />
* Xvid encoded videos unwatchable</p>
<p>Settings and Maintenance</p>
<p>* Streamlining user access to the Extras repository<br />
* Should remember position in packages list after installing package<br />
* Other Category appears twice<br />
* Installing many packages at a time via App Manager exhausts rootfs space<br />
* Artifacts (visual noise) when tapping screen in Screen Calibration<br />
* docpurge is not aware of /opt<br />
* Inconsistent layout on similar Sharing/VOIP applets<br />
* Background image settings not restored</p>
<p>Sharing</p>
<p>* Evernote uses to much space in root partition, should use /opt</p>
<p>Statusbar Widgets</p>
<p>* Volume slider doesn&#8217;t notice when you plug in headphones<br />
* Currently active connection should be first in Connections list</p>
<p>Synchronization</p>
<p>* First Synchronization between N900 and Exchange 2003 Server always fails<br />
* MfE spams screen with error messages when it cannot connect to the server<br />
* MfE wont keep Exchange account updated<br />
* Changing password on Exchange 2007 makes MfE go crazy<br />
* Company Directory not present<br />
* MfE is missing some CA cert symlinks on some devices (NuevaSync)<br />
* Initial sync fails with exchange 2007</p>
<p>System Analysis</p>
<p>* getbootstate bricks the device after 17 reboots if there are no normal boots in between them</p>
<p>System software</p>
<p>* Shaking device switches between landscape and portrait modes<br />
* Charger not recognized when plugged in when in Touch &amp; Key lock<br />
* Low power/battery beep does not sound if you&#8217;re on a call<br />
* Pin / lock code entry dialog reveals digits on backspace<br />
* Alarm clock does not wake me up when battery has died.</p>
<p>Telephony</p>
<p>* 3 Mobile SIM card rejected<br />
* Call forwarding settings not being saved<br />
* No pause before sending DTMF tones</p>
<p>Translations</p>
<p>* Change &#8216;TV uit&#8217; (TV out) to &#8216;TV-uitgang&#8217;<br />
* &#8220;Ładowanie&#8221; used without distinction between &#8220;&#8221;charging&#8221;" and &#8220;&#8221;loading&#8221;"<br />
* addr_va_lastname has a comma that it shouldn&#8217;t have<br />
* IP address field in WiFi advanced settings partially hidden (&#8220;&#8221;Recuperar automáticamente dirección IP&#8221;" string too long)<br />
* Some sentences in the User Guide don&#8217;t make sense<br />
* Wrong profile names in the User Guide<br />
* Delete dialog text missing a space<br />
* Polish string too long in UPnP browsing menu bar<br />
* Wrong PO Box translation for CZ language</p>
<p>Utilities</p>
<p>* Re-enable reset and/or reset-and-clear in osso-xterm<br />
* &#8220;&#8221;Already at minimum / maximum font size.&#8221;" not translated<br />
* File manager fails to show folder sizes beyond 999,9 MB<br />
* Clock alarm status icon is sometimes shown as dash (-)&#8221;<img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=408&#038;type=feed" alt="" /></p>
<a href='http://www.themaemo.com/nokia-n900-major-firmware-pr-1-1-out/' class='retweet vert' >Nokia N900 Major Firmware PR 1.1 out!</a>]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/nokia-n900-major-firmware-pr-1-1-out/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mkMMS First Third Party MMS for N900</title>
		<link>http://www.themaemo.com/mkmms-first-third-party-mms-for-n900/</link>
		<comments>http://www.themaemo.com/mkmms-first-third-party-mms-for-n900/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 12:20:49 +0000</pubDate>
		<dc:creator>Siraj</dc:creator>
				<category><![CDATA[Applications - Apps]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[maemo5]]></category>
		<category><![CDATA[mkmms]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[n900 camera]]></category>
		<category><![CDATA[n900 mms]]></category>
		<category><![CDATA[n900 mms application]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=395</guid>
		<description><![CDATA[mkMMS First Third Party MMS for N900
We all know N900 doesn&#8217;t yet feature a MMS sending capability. mkMMS is an application developed by Mohammed Sameer
The application is not yet finished. It&#8217;s in alpha stage but it&#8217;s working good. It lacks GUI and very limited in features.This application allows you to create a MMS and send [...]]]></description>
			<content:encoded><![CDATA[<a href='http://www.themaemo.com/mkmms-first-third-party-mms-for-n900/' class='retweet vert' >mkMMS First Third Party MMS for N900</a><div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fmkmms-first-third-party-mms-for-n900%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fmkmms-first-third-party-mms-for-n900%2F" height="61" width="51" /></a></div>
<p>We all know N900 doesn&#8217;t yet feature a MMS sending capability. mkMMS is an application developed by<strong> <a title="Index Page" href="http://foolab.org/">Mohammed Sameer</a></strong></p>
<p>The application is not yet finished. It&#8217;s in alpha stage but it&#8217;s working good. It lacks GUI and very limited in features.This application allows you to create a MMS and send your photo to another phone number via Nokia N900. With the current version you can attach only ONE, which can be jpg, png, gif or text file (txt). And at this point it&#8217;s still under development so we can get a full featured version very soon!. You can use it like this</p>
<p><code><strong>./mkmms  /home/temp/photo.jpg m-send-req.mms subject</strong></code></p>
<p>You can get a Copy of mkMMS here :<a href="http://home.foolab.org/files/mkmms.tgzhttp://home.foolab.org/files/mkmms.tgz"> </a><a href="http://home.foolab.org/files/mkmms.tgz">mkMMS</a><img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=395&#038;type=feed" alt="" /></p>
<a href='http://www.themaemo.com/mkmms-first-third-party-mms-for-n900/' class='retweet vert' >mkMMS First Third Party MMS for N900</a>]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/mkmms-first-third-party-mms-for-n900/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>HowTo: Fix the annoying &#8216;Unable to connect via USB. Device storage in use&#8217; error on the N900 without rebooting</title>
		<link>http://www.themaemo.com/howto-fix-the-annoying-unable-to-connect-via-usb-device-storage-in-use-error-on-the-n900-without-rebooting/</link>
		<comments>http://www.themaemo.com/howto-fix-the-annoying-unable-to-connect-via-usb-device-storage-in-use-error-on-the-n900-without-rebooting/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 22:19:49 +0000</pubDate>
		<dc:creator>archebyte</dc:creator>
				<category><![CDATA[Devices]]></category>
		<category><![CDATA[Hacks ,Tricks and Tips]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[maemo5]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[n900 softwares]]></category>
		<category><![CDATA[N900 Tricks]]></category>
		<category><![CDATA[Nokia N900 portrait mode]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=387</guid>
		<description><![CDATA[
If you connect the N900 to a computer via USB frequently, you will sooner or later encounter this error where the N900 will refuse to be used as external media.

This is because a program (or programs) is accessing files in the /home/user/MyDocs folder. To fix the problem, the program(s) in question needs to be found [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-fix-the-annoying-unable-to-connect-via-usb-device-storage-in-use-error-on-the-n900-without-rebooting%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-fix-the-annoying-unable-to-connect-via-usb-device-storage-in-use-error-on-the-n900-without-rebooting%2F" height="61" width="51" /></a></div>
<p>If you connect the N900 to a computer via USB frequently, you will sooner or later encounter this error where the N900 will refuse to be used as external media.</p>
<p><img class="aligncenter size-medium wp-image-389" title="Screenshot-20091217-222352" src="http://www.themaemo.com/wp-content/uploads/2009/12/Screenshot-20091217-222352-300x180.png" alt="Screenshot-20091217-222352" width="300" height="180" /></p>
<p>This is because a program (or programs) is accessing files in the /home/user/MyDocs folder. To fix the problem, the program(s) in question needs to be found and stopped. To find the program(s), open a root terminal and type</p>
<pre> lsof | grep MyDocs</pre>
<p>This will display the programs accessing the MyDocs folder something similar to this:</p>
<pre>Nokia-N900-42-11:~# lsof | grep MyDocs
sh        <span style="color: #ff0000;">3474</span>       user  cwd    DIR      179,1    65536       4326 /home/user/MyDocs/tmp</pre>
<p>The second column displays the process-ID of the program (in RED above). Now, terminate the program with this command (repeat for multiple programs):</p>
<pre>kill 3474</pre>
<p>Now, run the lsof command again (press UP arrow to go back) and make sure the program is not displayed. If it is still running, execute this:</p>
<pre>kill -9 3474</pre>
<p>Reconnect the USB cable and you should now be able to use the N900 as external media.<img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=387&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/howto-fix-the-annoying-unable-to-connect-via-usb-device-storage-in-use-error-on-the-n900-without-rebooting/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>HowTo: Launch a terminal app from a shortcut on Nokia N900 (Part 2)</title>
		<link>http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut-part-2/</link>
		<comments>http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut-part-2/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 07:54:17 +0000</pubDate>
		<dc:creator>archebyte</dc:creator>
				<category><![CDATA[Applications - Apps]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Hacks ,Tricks and Tips]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[maemo5]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[n900 faq]]></category>
		<category><![CDATA[n900 key tips]]></category>
		<category><![CDATA[n900 tips]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[xterm]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=373</guid>
		<description><![CDATA[
This tutorial will show you how to add an icon to the topx shortcut in Part 1.

Find/create a PNG image of dimension 48&#215;48. (google this)
Name the file topx.png
Save file to /usr/share/icons/hicolor/48&#215;48/hildon/ (you will need root access)
Modify the topx.desktop file to include the following line. The right side should be the name of file without the [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-launch-a-terminal-app-from-a-shortcut-part-2%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-launch-a-terminal-app-from-a-shortcut-part-2%2F" height="61" width="51" /></a></div>
<p>This tutorial will show you how to add an icon to the topx shortcut in <a href="http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut/" target="_blank">Part 1</a>.</p>
<ol>
<li>Find/create a PNG image of dimension 48&#215;48. (google <a href="http://images.google.com/images?imgtbs=z&amp;hl=en&amp;sa=1&amp;q=imagesize%3A48x48+filetype%3Apng+linux&amp;aq=f&amp;oq=&amp;aqi=&amp;start=0" target="_blank">this</a>)</li>
<li>Name the file topx.png</li>
<li>Save file to /usr/share/icons/hicolor/48&#215;48/hildon/ (you will need root access)</li>
<li>Modify the topx.desktop file to include the following line. The right side should be the name of file without the .png</li>
</ol>
<p><tt>Icon=topx</tt></p>
<p>The topx.desktop now looks like this:<br />
<tt>[Desktop Entry]<br />
Encoding=UTF-8<br />
Version=0.1<br />
Type=Application<br />
Terminal=true<br />
Name=topx<br />
Exec=/usr/bin/osso-xterm top<br />
Icon=topx<br />
X-Osso-Type=application/x-executable<br />
</tt></p>
<p>Save topx.desktop and reboot to see the icon for the shortcut in the Application Menu. If the icon does not show up, install a couple of apps from the Application Manager. This should update the icon-cache and display it.</p>
<div style="text-align:center"><img src="http://www.themaemo.com/wp-content/uploads/2009/12/Screenshot-20091211-194657.jpg" alt="" /></div>
<p><img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=373&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Nightmare of Pre Ordering the N900 through Dell</title>
		<link>http://www.themaemo.com/dell-pre-order-nightmare/</link>
		<comments>http://www.themaemo.com/dell-pre-order-nightmare/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 17:20:31 +0000</pubDate>
		<dc:creator>rm42</dc:creator>
				<category><![CDATA[Devices]]></category>
		<category><![CDATA[Editorial]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Nokia N900]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=358</guid>
		<description><![CDATA[When Dell representatives were presented with this evidence they simply said that they would have to “investigate” the matter and that they would get back in touch soon.  They also tried to pass the blame saying that they simply send orders automatically to Nokia for fulfillment as soon as the purchase takes place.  According to them, it was Nokia that was holding back deliveries to those that had pre-ordered from Dell.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fdell-pre-order-nightmare%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fdell-pre-order-nightmare%2F" height="61" width="51" /></a></div>
<div id="attachment_362" class="wp-caption alignnone" style="width: 610px"><img src="http://www.themaemo.com/wp-content/uploads/2009/12/Dell_Nightmare.jpg" alt="Dell Pre Order Nightmare" title="Dell_Nightmare" width="600" height="289" class="size-full wp-image-362" />
<p class="wp-caption-text">Dell Pre Order Nightmare</p>
</div>
<p>Picture this scene.  It is a Saturday afternoon of one of the busiest holidays in the country.  The week before, you found some coupons for a very nice discount at your family&#8217;s favorite restaurant.  Since you know that it is going to be difficult to get a table in such a busy holiday, you decide to get there earlier than usual.  You gather your kids and your wife and arrive to the restaurant nice and early.</p>
<p>Unfortunately, in spite of your foresight, the place is already full when you get there.  The hostess informs you that there is a waiting list and she asks if you would like to be put on it. You are told that the wait is expected to be about forty five minutes. You decide to agree and proceed to wait.  After some thirty five minutes have passed, you observe that some newly arrived clients are taken immediately to a table instead of being put on the waiting list. Then, you observe this happen a few more times. You approach some of these clients to ask them if maybe they had reserved over the phone, but they tell you that they didn&#8217;t.  They simply arrived as usual and were taken to their tables without any trouble. You go to the hostess to ask for an explanation and you are simply told that they are sorry but all the tables are being used.  You ask, “well how much longer do we have to wait?”  She says, “well, it looks like its going to take at least another forty five minutes.”  By now all the other restaurants are packed.  If you leave, the wait somewhere else will likely be even worst.  How would you feel then?</p>
<p>Well, a similar nightmare scenario has happened to many customers of Dell.  On November 5th, Dell issued a coupon that could be used in the purchase of the <a href="http://www.themaemo.com/nokias-maemo-os-the-next-big-wave/">highly anticipated</a> <a href="http://www.themaemo.com/tag/n900/" target="_blank">Nokia N900</a> mobile device.  The word on the internet got out and it didn&#8217;t take long before Dell had to remove the item from the website.  Everyone that managed to place an order felt very fortunate.  The item was expected to ship in a little over a month, but everyone decided that it was worth the wait.  Besides, every one thought that the device would likely end up shipping before then, as it often happens.</p>
<p>Sure enough, around November 21st , word began spreading about some orders starting to ship.  Of course, everyone got very excited.  Like when they announce that you plane is starting to board.  People who received their devices began posting their experiences, and everyone else waited excitedly for theirs to arrive.  Unfortunately, the days began to pass without their orders being shipped.</p>
<p>And then, some customers began reporting that orders they had just placed where actually shipping too.  That is right, orders that were being placed weeks after the original customers had pre-ordered, started to get their devices shipped!  You can imagine the confusion that arose.  People began to call Dell to ask them what was going on.  They simply answered that the device was not in stock.  Customers began consulting with one another to try to figure out what was really going on.</p>
<blockquote style="font-weight: bold"><p>That is right, orders that were being placed weeks after the original customers  had pre-ordered, started to get their devices shipped!</p></blockquote>
<p>Several of the customers that got their devices without having pre-ordered them were happy to help the rest.  They provided their order dates and delivered dates, and some customers were even able to get a few of the late ordering order numbers so that they could be verified.  When Dell representatives were presented with this evidence they simply said that they would have to “investigate” the matter and that they would get back in touch soon.  They also tried to pass the blame saying that they simply send orders automatically to Nokia for fulfillment as soon as the purchase takes place.  According to them, it was Nokia that was holding back deliveries to those that had pre-ordered from Dell.  When asked if there was a way for the customers to contact Nokia in order to get to the bottom of this failure to honor order dates, the answer was that unfortunately that was not possible.  Then, all of the sudden, everyone that had ordered on November 5th saw a change in their online order page.  The expected delivery date was moved to January 20th, 2010.</p>
<p>I personally was one of those customers.  It was at that time that I decided to do something about this.  I contacted Dell and asked for an explanation.  I received the same canned response, they would have to “investigate” the matter, but nothing could be done.  Outraged, I sent an email to Dell telling them that I was considering placing a complaint with the Better Business Bureau.  This was their response:</p>
<blockquote><p>Monday, December 14, 2009, 6:03 PM </p>
<p>Sir,</p>
<p>All efforts has been made to have the item shipped out but due to highly constrained backlog and a very limited inventory into the distribution centers the distribution centers will ship to the customers within their respective regions only.</p>
<p>As much as we wanted to ship the item out soon but we really cannot guarantee you since it will depend on the availability of the item. Since you are in a hurry to get this item, the only option here is to cancel order and you can just buy one from a local store. Thank you.</p>
<p>Regards,</p>
<p>[***********]<br />
Dell Inc. | Americas Customer Care<br />
Work Days: Mon &#8211; Thurs<br />
Work Hours: 08:00a.m.-7:00p.m.CST </p></blockquote>
<p>To that, I replied:</p>
<blockquote><p>
Monday, December 14, 2009 7:25 PM</p>
<p>Dear Ms *********,</p>
<p>Thank you for your response. I do not want to cancel my order. You see, the issue is not that I am in a hurry to get the phone. What is upsetting is the fact so many people who ordered much latter than me got their phone. Look at this two orders for example:</p>
<table border=0>
<tr>
<td>OrderNumber</td>
<td>OrderDate</td>
<td>Status</td>
</tr>
<tr>
<td>999999999</td>
<td>11/19/2009</td>
<td>Shipped</td>
</tr>
<tr>
<td>999999999</td>
<td>11/25/2009</td>
<td>Shipped</td>
</tr>
</table>
<p>I will wait as long as I have to wait, but I am not happy about the situation. There is obviously something very wrong about the way the orders are being processed. My desire is for this situation to be rectified so that in the future other customers do not have to deal with this sort of issues. I thank you for continuing to try to resolve this situation and to rectify what caused it in the first place.</p>
<p>Sincerely,</p>
<p>[rm42] </p></blockquote>
<p>Several days went by with no word from Dell.  By now, I had put my self in contact with some of the customers that were in the same situation that I was and offered them to place a join-complain to the Better Business Bureau, thinking that maybe that way it would be taken more seriously (since then I have been informed that it is actually better to have each individual file his own complaint).  Several customers agreed and gave me their information.  I also contacted some of the users that claimed to have had their devices shipped without having to pre-order, and they too were willing to share their order numbers, order dates, and delivery dates with me.  Armed with that, I wrote another email to Dell.</p>
<blockquote><p>
Wednesday, December 16, 2009 11:50 PM<br />
Dear Ms E*********,</p>
<p>I take it that you have no news regarding the shipment of the N900 since I have not heard from you yet. That is OK. I am resigned to wait it out. However, would you not agree that I am entitled to some form of compensation for all the trouble and frustration that Dell&#8217;s mismanagement of my order has caused me? </p>
<p>Think of it this way. Imagine that you go out with your family to a restaurant for dinner. Upon arriving you are told that there is a waiting list and you are asked if you would like to be put on it. You are told that the wait is expected to be about half an hour. You decide to agree and proceed to wait. After 20 minutes have passed, you observe that some newly arrived clients are taken immediately to a table instead of being put on the waiting list. You observe this happen a few more times. You approach some of this clients to ask them if they had maybe reserved over the phone, but they tell you that they simply arrived and were taken to their tables without any trouble. You go to the receptionist to ask for an explanation and you are simply told that they are sorry but all the tables are being used. How would you feel then?</p>
<p>Well isn&#8217;t that what is happening in my and many others cases? Here is a list of people that are in the same situation that I am:</p>
<table border=0>
<tr>
<td>Name</td>
<td>OrderNumber</td>
<td>OrderDate</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
<tr>
<td>**** *****</td>
<td>999999999</td>
<td>11/5/2009</td>
</tr>
</table>
<p>And here are just some of the orders that were fulfilled with devices that should really have been shipped to one of us instead.</p>
<table border=0>
<tr>
<td>OrderNumber</td>
<td>OrderDate</td>
<td>Status (by 12/8/09)</td>
</tr>
<tr>
<td>999999999</td>
<td>11/26/09</td>
<td>Shipped</td>
</tr>
<tr>
<td>999999999</td>
<td>11/25/09</td>
<td>Shipped</td>
</tr>
<tr>
<td>999999999</td>
<td>11/19/09</td>
<td>Shipped</td>
</tr>
</table>
<p>So, tell me, how is Dell going to try to repair our relationship as customers?</p>
<p>Sincerely,</p>
<p>[rm42]</p></blockquote>
<p>As I write these words, I have not yet received any response from Dell.  Interestingly, one customer was able to get through to Nokia to have this matter addressed.  This is the email he received from Nokia:</p>
<blockquote><p>Thank you for e-mailing the Nokia Care Contact Center.</p>
<p>With regard to your inquiry about the delivery date, basically it is between you and Dell, since you placed the pre order with Dell and not with Nokia. We deliver the units to Dell and Dell delivers it in return to their customers. We will have no business delivering it to their customers, since it is not our customers. We will not know who placed the pre order with them, that is basically internal process with Dell. We suggest that you contact Dell, however it is evident that they point it to Nokia to avoid blame from customers, they might have preferred customers.</p>
<p>If you have any additional questions, please don’t hesitate to contact us again. To ensure proper handling of your case, kindly continue using the current subject line.</p>
<p>Thank you very much for your email. Have a great day!</p>
<p>Kind regards,<br />
Rosalie L.<br />
E-mail Specialist<br />
Nokia Inc. </p></blockquote>
<p>So now I ask you, what do you think is going to be Dell&#8217;s next move, if any?  What do you think their next move should be?  What would you do in our situation?<img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=358&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/dell-pre-order-nightmare/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python for Newbies &#8211; Tutorial &#8211; Part Two</title>
		<link>http://www.themaemo.com/python-for-newbies-part-two/</link>
		<comments>http://www.themaemo.com/python-for-newbies-part-two/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 20:47:37 +0000</pubDate>
		<dc:creator>rm42</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Editorial]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[nokia]]></category>
		<category><![CDATA[nokia n900]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=214</guid>
		<description><![CDATA[This is part two of the Python for Newbies tutorial. Part One can be found here. The content of this tutorial is provided under the Creative Commons Attribution-Share Alike 3.0 license.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fpython-for-newbies-part-two%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fpython-for-newbies-part-two%2F" height="61" width="51" /></a></div>
<p>This is part two of the <a href="http://www.themaemo.com/python-for-newbies/" target="_blank">Python for Newbies tutorial</a> . Part One can be found <a href="http://www.themaemo.com/python-for-newbies/">here</a>. The content of this tutorial is provided under the Creative Commons Attribution-Share Alike 3.0 license:</p>
<p>http://creativecommons.org/licenses/by-sa/3.0/</p>
<p>http://creativecommons.org/licenses/by-sa/3.0/legalcode</p>
<p><a name="Functions"></a></p>
<h2>Functions</h2>
<p>Functions are simply a set of commands or statements grouped together as a unit with a name that can be called on by other parts of the program (or even by other programs) to accomplish a certain task. Since the statements inside a function do not have to be rewritten every time the steps they perform are needed, our programs are smaller and easier to maintain. We have already used several functions that are built in to the Python core. For example, we have used the del function to delete items from Python lists and dictionaries, the tuple function to convert a string into a tuple, several math functions, and others. However, we are now going to learn how to create our own functions. Functions are simple, but there are a few new associated concepts that you will have to understand.<span id="more-214"></span></p>
<p><a name="Defining a function"></a></p>
<h3>Defining a function</h3>
<p>Here is a brief example that we can examine:<br />
<code language="python"><br />
&gt;&gt;&gt; def average(num1, num2):<br />
</code><br />
<code language="python">...     avrg = (num1 + num2) / 2</code></p>
<p><code language="python">...     return avrg</code></p>
<p>This is a small little function that calculates the average between two numbers and returns the result Notice that, as all the compound statements that we have seen, a function definition has a header that ends with a colon. The header begins with the def statement, followed by the name of the function to be. After that, we have something that you should be able to recognize, a tuple, nothing else, nothing more. That tuple is used to contain the parameters of your function. What are parameters? Well, parameters are values that can be passed to your function (and that your function will expect when called) for it to do something with them. In Python, those parameters can be anything you want: a number, a string, a list, a dictionary, a file, etc. Parameters can have default values too. For example, we could define a function with a header like this:<br />
<code language="python"><br />
def personal_info(name, phone, country = 'USA'):<br />
</code><br />
The third parameter of this function has a default value, the string &#8216;USA&#8217;. That means that when calling this function the third parameter is optional. We could call the function like this:<br />
<span style="font-family: Courier New,monospace;"><br />
personal_info(Joe, 1234-5678)<br />
</span><br />
The function would accept the call and use &#8216;USA&#8217; as the value for the third parameter. Of course, we would also have the option of using a different third parameter, like this:<br />
<code language="python"><br />
personal_info(Bob, 987-6543, 'UK')<br />
</code><br />
So, defaults can come in very handy.</p>
<p>Notice that on the first function we defined above (average) the result was returned to the calling program with a specific statement, the <span style="font-family: Courier New,monospace;">return</span> statement. Why is that? Why couldn&#8217;t we just be satisfied with having the variable avrg as the container of the result and use it in other parts of the program? In one word: namespaces.</p>
<p><a name="Namespaces and Scope"></a></p>
<h3>Namespaces and Scope</h3>
<p>Python, as most programming languages, stores names defined inside a function in a separate place from where it stores other names. This different spaces are called, appropriately so, namespaces or scopes. You can think of namespaces as Dictionaries that contain names and its values as key-value pairs. Whenever a function is defined an associated namespace is created. For reasons beyond the scope of this tutorial (pun intended), in Python, names are only accessible to your code if they are defined in one of the following four scopes:</p>
<ul>
<li>The first one is called the Built-in scope. This scope is where all the core functions and constants of Python are defined. It is always available to you from anywhere in your code.</li>
<li>The second one is the Global scope. This is the namespace at the top level of a Python module. (You can see the Modules section if you want, or, for now, think of a module as a file with Python code.) In other words, any name defined outside a function or a class (we will cover classes latter as well) is in the Global scope. Names defined in this scope, like those in the built-in scope, are always available from anywhere in the module that contains it.</li>
<li>The third one is the local namespace. This is where names defined in a function reside. As mentioned before, names defined inside a function are only accessible from within that function. They are automatically destroyed once the function stops running.</li>
<li>The last namespace is called the nested scope. This namespace is defined as the namespace of the enclosing scope in which it was defined. That is, if inside a function you make reference to a name that Python does not find in the local namespace, it will then look to see if the name is defined in the enclosing namespace &#8211; the nested namespace.</li>
</ul>
<p>Here is an example of how the nested namespace would work:<br />
<span style="font-family: Courier New,monospace;"><br />
operation = 1     # Variable defined in the Global namespace. Always accessible.</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; def some_function(operation, num1, num2):</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     if operation == 1:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         x=num1 &nbsp;&nbsp;&nbsp;&nbsp;#Variables defined in some_function&#8217;s local namespace.</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         y=num2</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         def multiply():</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;             print x * y &nbsp;&nbsp;&nbsp;&nbsp;    # x and y are not in the local namespace of multiply.</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         multiply()<br />
</span><br />
Without nested scopes, this function would report an error, because x and y would not be in the local namespace of multiply, or in the global namespace, or in the built-in namespace. Of course, one could pass the value of x and y as parameters to the multiply function, but certain styles of programming (most specifically functional style programming) are much happier with access to nested scopes. (In other words you may never need to use nested scopes, but at least you now know they are there).</p>
<p>Since variable assignment inside a function takes place in the local namespace, one cannot reassign (change) the value of a Global variable inside a function. Let&#8217;s look at an example.<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; value= 1</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; def change_value():</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     value = 2</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print value</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; change_value()</span></p>
<p><span style="font-family: Courier New,monospace;">2</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; print value</span></p>
<p><span style="font-family: Courier New,monospace;">1<br />
</span><br />
As you can see, when we assigned <span style="font-family: Courier New,monospace;">2</span> as the value of <span style="font-family: Courier New,monospace;">value</span> inside the <span style="font-family: Courier New,monospace;">change_value</span> function, the assignment took place only in the local namespace of the function. The Global variable <span style="font-family: Courier New,monospace;">value</span> remained unchanged. There is, however, a dirty little workaround that should probably be avoided as much as possible in truly efficient and well designed code. Some claim that global variables should only be changed by direct assignment at the global level, whether through direct assignment, or by the value returned from a function. (For example: <span style="font-family: Courier New,monospace;">value=change_value()</span>) In any case the workaround is the use of the <span style="font-family: Courier New,monospace;">global</span> statement. Let&#8217;s try it.<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; var = 1</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; def func(val):</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     global var</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     var =val*2</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; func(3)   </span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; print var   </span></p>
<p><span style="font-family: Courier New,monospace;">6<br />
</span><br />
So, thanks to the use of the global statement, our function successfully changed the value of a variable defined in the Global namespace. If <span style="font-family: Courier New,monospace;">var</span> did not exist before the function call, the function would simply create it.</p>
<p>To clarify the scope order, know that Python will look for names according the LNGB rule. It will first look for the name definition in the local namespace, if not found, it will then look for it in the nested scope, then in the global scope, and finally in the built-in scope. If not found, it will return an error.</p>
<p><a name="Modules"></a></p>
<h2>Modules</h2>
<p>We mentioned modules in the previous section. Basically, Python modules are files with Python code. Modules are the natural way to group related code. So far, all of the built-in Python functions we have seen are included as part of the core Python functionality. However, there are a lot more functions and capabilities included in a Python distribution. Most of them are included as separate modules that one has to &#8220;import&#8221; in order to use. Let&#8217;s look at an example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; import os</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; os.getcwd()</span></p>
<p><code language="python">'/home/me'<br />
</code><br />
The first line, above, uses the import statement to gain access to all the classes, functions and variables defined in a module called os. (As you can imagine the os module contains code related to the use of the operating system.) Notice that to access the getcwd function (get current working directory), all we had to do was type the name of the module, add a period, and type the name of the function. Let&#8217;s look at another function in this module:<br />
<code language="python"><br />
&gt;&gt;&gt; os.chdir('/home/me/MyDocs')</code></p>
<p><code language="python">&gt;&gt;&gt; os.getcwd()</code></p>
<p><code language="python">'/home/me/MyDocs'<br />
</code><br />
Here we used the chdir function to change our current working directory to &#8216;/home/me/MyDocs&#8217;. There are a couple of things to pay attention to here. First, notice that the chdir function expects a string as a parameter. That is why we used quotes to surround the path. Notice too that we used a forward slash rather that the backslash commonly used in windows. The reason for this is that in Python the backslash is a character with a special meaning &#8211; it is the &#8216;escape&#8217; character. Besides, in Linux, the OS of the N900, the forward slash is the standard path separator. (If you want your code to be portable between your N900 and Windows use os.sep instead of /.)</p>
<p>To remove a module that we have imported we again can use the handy del function:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; del(os)<br />
</span><br />
We could also import one or more specific items from a module. This is how we would do that:<br />
<code language="python"><br />
&gt;&gt;&gt; from os import listdir, getcwd</code></p>
<p><code language="python">&gt;&gt;&gt; listdir(getcwd())</code></p>
<p><code language="python">['somefile.txt', 'Dir', 'Dir2', 'File', 'File.txt']<br />
</code><br />
The listdir function is imported directly into the local scope. This means that we can use it directly without reference to the module it was originally in. This can be convenient sometimes, but is not considered a &#8216;best practice&#8217; way of doing things. Nevertheless, there are some modules designed specifically to be imported into the local space. For example some Graphical User Interface (GUI) related modules are like that.</p>
<p>Here is another example, one we made reference to earlier.<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; from __future__ import division</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; 7/2</span></p>
<p><span style="font-family: Courier New,monospace;">3.5<br />
</span><br />
Here you see how to make the N900&#8217;s version of Python handle division as Python 3.x does.</p>
<p>There are dozens of modules included in a Python distribution. This collection of modules is called Python&#8217;s Standard Library. It is a very good idea to become familiar with their names and what they are for, at least it is good to know what are the most commonly used ones. Probably the best way to do this is by looking at the documentation that is installed with Python. In particular, looking at the &#8220;<a href="http://www.python.org/doc/2.5/modindex.html" target="New">Global Module Index</a>&#8221; can be very useful. It contains links to detail explanations for each module of the Standard Python Library. There are also lots of third party developed modules and packages, such as the Windows extension modules that give access to all the win32 API, and to several Windows specific features. Others are the PyQt package and the PyGTK packages. These are the packages used for building GUI interfaces on the N900. One more that I you look at is the py2exe package. This one allows you to distribute your Python programs as executable files to users that do not have Python installed. Of course, you shouldn&#8217;t need that for your N900 programs.</p>
<p>Naturally, we can make our own modules simply by creating a file with Python code in it. When we import that module, all its code is executed, whether it is code that defines a function, or simple Python expressions. For example add the following commands into a regular text file, and name the file test.py:</p>
<p><code language="python">def greet(name):</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;print "Hello there, %s" %(name)</code></p>
<p><code language="python">greet('John')<br />
</code><br />
Now, in the Python interpreter, import your test module. Note that, since your module is likely not in the Python path, you may have to change your current working directory to the folder where you saved test.py so that Python can find it (The Python path is where Python searches, in addition to the current working directory, when trying to import a module.):<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; import test</span></p>
<p><span style="font-family: Courier New,monospace;">Hello there, John<br />
</span><br />
Two things happened when we imported our module: The <code language="python">greet</code> function was defined, and the <code language="python">greet('John')</code> function call executed. Now, we can continue to use the <code language="python">greet</code> function with other function calls. For example:<br />
<code language="python"><br />
&gt;&gt;&gt; test.greet('Marla')</code></p>
<p><code language="python">Hello there, Marla</code></p>
<p><code language="python">&gt;&gt;&gt; test.greet('Michael')</code></p>
<p><code language="python">Hello there, Michael<br />
</code><br />
Now, open a Terminal session and go to the directory that contains your module. Then, try running test.py as a script. For example:<br />
<code language="python"><br />
/home/m/MyDocs/Test&gt; python test.py</code></p>
<p><code language="python">Hello there, John<br />
</code><br />
The same two things happened. But, of course, since Python terminates when it is finished running the script, we can not continue using it to call the <code language="python">greet</code> function.</p>
<p>We can also make our scripts accept command line parameters so that it uses them at run time. For example, save this as test.py:<br />
<code language="python"><br />
import sys</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;for item in sys.argv:</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print item<br />
</code><br />
We could then run this script with a call like this:<br />
<code language="python"><br />
/home/m/MyDocs/Test&gt;python test.py First "Second" "And third"</code></p>
<p><code language="python">test.py</code></p>
<p><code language="python">First</code></p>
<p><code language="python">Second</code></p>
<p><code language="python">And third<br />
</code><br />
The parameters we give to our scripts when calling them are stored in a list called <span style="font-family: Courier New,monospace;">argv</span> accessible through the <span style="font-family: Courier New,monospace;">sys</span> module. The first parameter (<span style="font-family: Courier New,monospace;">argv[0]</span>) is the name of the script itself. So, in our example above, <span style="font-family: Courier New,monospace;">argv[1]</span> would be the parameter <span style="font-family: Courier New,monospace;">&#8220;First&#8221;</span>.</p>
<p>Generally, the conceptual purpose of a module is to store variables, function definitions and classes for use in other Python programs when needed. But, as you can see, there is no real difference between a module and a regular Python script. You can import any of your Python programs as a module and you can then use the functions and classes defined in them on any program where you need them. However, there is a right way to organize your code inside a module for this to be effective.  To illustrate this, lets take a look at another sample Python file, lets call it unames.py.<br />
<code language="python"><br />
import sys</code></p>
<p><code language="python">def full_name(first, second):</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;full = first + " " + second</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;return full</code></p>
<p><code language="python">def greet(name):</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;print "Hello there, %s" %(name)</code></p>
<p><code language="python">fname = full_name(sys.argv[1], sys.argv[2])</code></p>
<p><code language="python">greet(fname)<br />
</code><br />
What we have here is a couple function definitions, a function call that results in variable assignment, and another function call. Now, say that you are creating a new program and want to use those two functions. You could simply <code language="python">import unames</code> and access them. However, you would then have a new <code language="python">fname</code> variable and the <code language="python">greet(fname)</code> function call executed, and that may not be what you want. So, in order to make sure our Python modules are reusable, we need to have a way of keeping our function and class definitions separate from the calls and we need to have a way of avoiding those calls from executing when the module is imported. Fortunately, there is a very easy way to do this. Just reorganize the code like this:<br />
<code language="python"><br />
def full_name(first, second):</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;full = first + " " + second</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;return full</code></p>
<p><code language="python">def greet(name):</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;print "Hello there, %s" %(name)</code></p>
<p><code language="python">if __name__ =='__main__':</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;import sys</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;fname = full_name(sys.argv[1], sys.argv[2])</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;greet(fname)<br />
</code><br />
Notice that the import statement and the two function calls are only executed when a special condition is met &#8211; that the file is being run as a script. This allows you to place all your function and class definitions at the top of your modules and at the very end you can place any code that is to run when the file is run as a script, and that is not to run when the file is simply imported as a module.</p>
<p>One last thing to remember about modules is that if you are using a module and make changes to the code while you are using them in an interactive Python session, you will only be able to use the changes if you reload the module. To do this you have to either delete the module from Python&#8217;s memory (using the del function) and import it again, or use the reload function like this:<br />
<code language="python"><br />
&gt;&gt;&gt; reload(test)<br />
</code><br />
Now that we are talking about files, why don&#8217;t we take a look at how we work with files from Python code.</p>
<p><a name="Working with files"></a></p>
<h2>Working with files</h2>
<p>Working with files implies being able to open, read, and write files. Python has everything needed to do that and be able to process them with ease. In Python, files are a built in object type (like lists, dictionaries, etc). We create file objects using the open function. Depending on how we do this, we can either open an existing file or create a new one. Let&#8217;s first create a new file:<br />
<code language="python"><br />
&gt;&gt;&gt; f = open('MyFile.txt', 'w')<br />
</code><br />
At this point the variable <span style="font-family: Courier New,monospace;">f</span> represents a new file object that has been created in the file system at the current working directory. Notice that the <span style="font-family: Courier New,monospace;">open</span> function expects two parameters. The first parameter is the path and file name, provided as a string. The second parameter is also a string. It can be either <code language="python">'w'</code>, for write, or <code language="python">'r'</code>, for read. Let&#8217;s now write something into our file:<br />
<code language="python"><br />
&gt;&gt;&gt; f.write('This is a line inside the file.\nThis is another line.\n')</code></p>
<p><code language="python">&gt;&gt;&gt; f.write('This is the third line.')</code></p>
<p><code language="python">&gt;&gt;&gt; f.close()<br />
</code><br />
Now, if with a text editor we take a look at the file we created, the file should look like this:<br />
<code language="python"><br />
This is a line inside the file.</code></p>
<p><code language="python">This is another line.</code></p>
<p><code language="python">This is the third line.<br />
</code><br />
As you have probably figured out already, the <code language="python">'\n'</code> combination represents the &#8216;new line&#8217; character. The write method of the file object allows us to add strings to our files. And the close method simply closes it. Easy, right? Now what if you wanted to change something in the file we just created? Well, here is an example:<br />
<code language="python"><br />
&gt;&gt;&gt; f = open('MyFile.txt', 'r')</code></p>
<p><code language="python">&gt;&gt;&gt; file_contents = f.readlines()     #The readlines method returns a list of lines.</code></p>
<p><code language="python">&gt;&gt;&gt; f.close()</code></p>
<p><code language="python">&gt;&gt;&gt; file_contents     #Just to show you the contents of file_contents.</code></p>
<p><code language="python">['This is a line inside the file.\012', 'This is another line.\012', 'This is the third line.']</code></p>
<p><code language="python">&gt;&gt;&gt; f = open('MyFile.txt', 'w')     #Now we open it again to write our changes.</code></p>
<p><code language="python">&gt;&gt;&gt; for line in file_contents:</code></p>
<p><code language="python">...     new_line = line.replace("line", "set of words")</code></p>
<p><code language="python">...     f.write(new_line)</code></p>
<p><code language="python">...</code></p>
<p><code language="python">&gt;&gt;&gt; f.close()<br />
</code><br />
As you can see, to edit a file we first have to read its contents, close the file, and open it again to write. If we open an existing file with write mode, we really are just over-writing it with a new blank file of the same name. So, after executing the commands above, we have new file, in the same location, with the same name, and almost the same contents. The only difference is that we replaced the occurrences of &#8220;line&#8221; with &#8220;set of words&#8221;.</p>
<p>Those are the basics of file manipulation, and that is all we are going to cover. Now, through this tutorial you may have notice that we referred several times to something called classes and objects. Let&#8217;s take a very brief look at this subject.</p>
<p><a name="Classes and Objects"></a></p>
<h2>Classes and Objects</h2>
<p>There are several theories of what is the best way to program. One method of programming is called Object Oriented Programming (OOP). Python was designed from the ground up, with OOP concepts in mind. Yet, Python doesn&#8217;t force us to program this way. OOP in Python is optional. Stil, it may be a good thing to give you a glimpse of how this works.</p>
<p>We have already seen how we can save statements variables and functions inside a module, and then access them in our code by importing the module. Another way to do this is by using the class statement. Let&#8217;s look at an example:<br />
<code language="python"><br />
&gt;&gt;&gt; class Address:</code></p>
<p><code language="python">...     def setStreet(self, value):</code><br />
<code language="python">...         self.Street = value</code></p>
<p><code language="python">...     def setCity(self, value):</code><br />
<code language="python">...         self.City = value</code></p>
<p><code language="python">...     def display(self):</code><br />
<code language="python">...         print "The address is:"</code><br />
<code language="python">...         print self.Street</code><br />
<code language="python">...         print self.City<br />
</code><br />
As you can see we have defined the class Address. In it we have defined three methods (method is how a function inside a class is generally called). You probably notice that the first parameter for each of the methods is the word &#8220;self&#8221;. Why? Well, to understand that, you have to understand what classes are for. A class is defined so that we can produce objects based on them. You can think of the class definition as the DNA of its objects. We can create as many objects as we want from a class, and they will all be like little clones of each other. Each object we create is referred to as an instance object. Once an instance is created, it can start to have its own particular characteristics, different values, etc. Each object is now an independent &#8217;self&#8217;. So, the self we use when defining the methods inside a class refer to the particular instance the actions we are defining should apply to. If this is &#8220;all too wonderful&#8221; for you, don&#8217;t worry. Just remember that you have to use self as the first parameter of your method definitions. If you don&#8217;t, Python will kindly remind you with an error message when you try to use the method.</p>
<p>Let&#8217;s now create an instance (object) from our class:<br />
<code language="python"><br />
&gt;&gt;&gt; address = Address()<br />
</code><br />
That is all there is to it. At this point address is an instance object based on the clsAddress class. It can now start accepting its own personal data. Let&#8217;s give it some now:<br />
<code language="python"><br />
&gt;&gt;&gt; address.setStreet('157 Royal Road')</code></p>
<p><code language="python">&gt;&gt;&gt; address.setCity('NY')<br />
</code><br />
Notice that we have access to the methods defined in our class. Let&#8217;s display the contents of our object now:<br />
<code language="python"><br />
&gt;&gt;&gt; address.display()</code></p>
<p><code language="python">The address is:</code></p>
<p><code language="python">157 Royal Road</code></p>
<p><code language="python">NY<br />
</code><br />
You may remember, from our earlier analysis of scopes, that functions have their own local scope. Variables inside a function are destroyed as soon as the function stops running. The same is true of methods (since they are simply functions too). That is why when assigning a value to a variable inside a method, if we want it to be available latter, we qualify the variable with, again, the word self. This is as if we told Python to store the value of the variable in the global scope of our object. That&#8217;s right, objects have their own internal global namespaces. The value of variables defined this way can be retrieved by making direct reference to the particular object namespace like this:<br />
<code language="python"><br />
&gt;&gt;&gt; address.Street</code></p>
<p><code language="python">'157 Royal Road'</code></p>
<p><code language="python">&gt;&gt;&gt; address.City</code></p>
<p><code language="python">'NY'<br />
</code><br />
Of course, we have been using this feature all along in this tutorial, but now you should have a better idea of why. Here is another way to look at the contents of an object:<br />
<code language="python"><br />
&gt;&gt;&gt; dir(address)</code></p>
<p><code language="python">['Street', 'City']<br />
</code><br />
The dir function returns a list of all the names defined in the object. Finally, here is another little trick to help inspect objects:<br />
<code language="python"><br />
&gt;&gt;&gt; address.__dict__</code></p>
<p><code language="python">{'Street':'157 Royal Road', 'City':'NY'}<br />
</code><br />
Every object has to have a built-in location to store its instance names and values. That place is the __dict__ dictionary. And, yes, it is just a regular dictionary object itself.</p>
<p>So, just remember, in Python, everything is an object. Even class definitions are objects:<br />
<code language="python"><br />
&gt;&gt;&gt; Address.__dict__</code></p>
<p><code language="python">{'display': , 'setStreet': , '__doc__': None, 'setCity': , '__module__': '__main__'}<br />
</code><br />
There is much more we could talk about in this subject, but this is all we are going to cover. Time is precious, and we still have a few more things to cover. For example, in this section we made reference to the fact that Python has the capacity of displaying errors. Errors are simply unavoidable in programming. So, let&#8217;s take a quick look at them now.</p>
<p><a name="Errors and Error Handling"></a></p>
<h2>Errors and Error Handling</h2>
<p>What we commonly refer to as &#8216;errors&#8217; in programming are the accidental mistakes we make in our code that yield either the wrong result, or no result at all. Some programming languages leave it at that. They make no attempt at trying to explain why the program did not do what you expected. That is why people have developed special programs called &#8216;debuggers&#8217; to provide some help in finding where those errors occur. Thankfully, Python is very helpful in this regard. When you commit an error in programming that would result in a break of the flow of execution, Python displays messages to help you try to identify the type and location of the error. For example:<br />
<code language="python"><br />
&gt;&gt;&gt; print something</code></p>
<p><code language="python">Traceback (most recent call last):</code></p>
<p><code language="python">File "", line 1, in ?</code></p>
<p><code language="python">NameError: There is no variable named 'something'<br />
</code><br />
The error message, in this case, consists of three lines:</p>
<ol>
<li>The first line simply tells you the way the error message is organized (most recent call last). This is because some errors occur, for example, when your program makes a function call, that itself calls another function, that calls another certain function (where the error resides). Python will trace back the error, letting you know what the original call was, what the next call was, and what the final call (where the error occurred) was.</li>
<li>The second line tells you the file and line number of where the error was found. In this case, since we are using the Interactive Command Prompt, it refers to the file as stdin (standard input &#8211; right now, the keyboard input).</li>
<li>Finally, the last line tells us the type of error (<span style="font-family: Courier New,monospace;">NameError</span>), and what the error was.</li>
</ol>
<p>So, as you can see, it is very easy to track down your errors, most of the time. Of course, if the error in your program is found in its logic, rather than in its semantics, there is very little Python can do to help you.  There are some other packages designed for that.  For example, there is a module called <span style="font-family: Courier New,monospace;">unittest</span> that allows one to do something called &#8220;Unit Testing&#8221;. This is a very popular to check for errors in Python programmnig.  But, that is beyond the scope of this tutorial.</p>
<p>The errors that Python catches and displays, as we saw above, are really a subcategory of the larger category called exceptions. Some of the most common standard exceptions in Python are the following (there is a complete list in the manual):</p>
<table border="1">
<tbody>
<tr>
<th>Error Type</th>
<th>Description</th>
</tr>
<tr>
<td>IOError</td>
<td>generated when an I/O operation fails.</td>
</tr>
<tr>
<td>ImportError</td>
<td>generated when a module import fails.</td>
</tr>
<tr>
<td>IndexError</td>
<td>generated when an attempt is made to access a non-existent element index.</td>
</tr>
<tr>
<td>KeyError</td>
<td>generated when an attempt is made to access a non-existent dictionary key.</td>
</tr>
<tr>
<td>MemoryError</td>
<td>generated when an out-of-memory error occurs.</td>
</tr>
<tr>
<td>NameError</td>
<td>generated when an attempt is made to access a non-existent variable.</td>
</tr>
<tr>
<td>SyntaxError</td>
<td>generated when the interpreter finds a syntax error.</td>
</tr>
<tr>
<td>TypeError</td>
<td>generated when an attempt is made to run an operation on an incompatible object type.</td>
</tr>
<tr>
<td>ValueError</td>
<td>generated when function receives an argument that has an inappropriate value.</td>
</tr>
<tr>
<td>ZeroDivisionError</td>
<td>generated when an attempt is made to divide by zero.</td>
</tr>
</tbody>
</table>
<p>In Python exceptions can be intercepted quite easily. The way this is done is by the try/except/else construct. For example:<br />
<code language="python"><br />
&gt;&gt;&gt; try:</code></p>
<p><code language="python">...     print something</code></p>
<p><code language="python">... except NameError:</code></p>
<p><code language="python">...     print "You should have defined it first!"</code></p>
<p><code language="python">...</code></p>
<p><code language="python">You should have defined it first!<br />
</code><br />
As you can see, we were able to trap the error and tell Python what to do about it. We could exit the program at this time, but in this case we just printed a message. The flow of execution would continue outside of the try statement.</p>
<p>When we add an else block to a try construct, the code inside the else block is executed only if no exception is generated by the try construct. Here is an example:<br />
<code language="python"><br />
&gt;&gt;&gt; try:</code></p>
<p><code language="python">...     numb1 = int(raw_input("Type a number"))</code></p>
<p><code language="python">... except ValueError:</code></p>
<p><code language="python">...     print "You should have typed a number."</code></p>
<p><code language="python">... else:</code></p>
<p><code language="python">...     print "Good job %i is a number." %(numb1)<br />
</code><br />
The first line in the try statement tries to convert the input from the raw_input function into an integer number. It will only work if the input received is in the form of a number. Anything else will generate a ValueError, which we can dutifully intercept. If no error is found the else block is executed and the flow of the program continues outside the try statement.</p>
<p>A variation of the previous statement is the try/finally statement (no else allowed on this one). It consists of one try block followed by a finally block. The finally block always executes no matter what happens. So, this construct is useful when there is something that you want to make sure happens before the program exits. For example, you may want to make sure that some files are closed, or that some data is saved. If an exception is raised during the execution of the try statement, the flow of execution jumps to the finally block, and then it is returned the normal exception handling mechanism. For example, if we had something like this:<br />
<span style="font-family: Courier New,monospace;"><br />
try:</span></p>
<p><span style="font-family: Courier New,monospace;"> </span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;try:</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;statements&#62;</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;finally:</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#60;statements&#62;</span></p>
<p><span style="font-family: Courier New,monospace;">except:</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&#60;statements&#62;<br />
</span><br />
In this example, if an exception is found in the try/finally statement, once the finally block is executed, the exception would be propagated to the try/except statement for it to be handled. If not trapped by the except statement, it would be propagated further up until it finally is handled by the Python&#8217;s standard exception handling mechanism, thus ending the program.</p>
<p>There is a lot more we could learn about errors or exceptions, but this at least gives you a glimpse into the basics. Let&#8217;s now try to gather a few miscellaneous tidbits that will be useful to you as write your own programs.</p>
<p><a name="Other common built-in functions"></a></p>
<h2>Other common built-in functions</h2>
<p>In this section we are going to cover a few functions that we did not cover before. These are some of the most commonly used built-in functions from the Python core.</p>
<p>Note:<br />
To see a list of all the built-in functions in the Python core use this command: <span style="font-family: Courier New,monospace;">dir(__builtins__)</span></p>
<p>Let&#8217;s first look at the len function. Its purpose is to tell us the length of a sequence. In other words, how many items are in it. This is how it works:<br />
<code language="python"><br />
&gt;&gt;&gt; L = [1, 2, 3, 4]</code></p>
<p><code language="python">&gt;&gt;&gt; len(L)</code></p>
<p><code language="python">4<br />
</code><br />
So, as you can imagine, the len function is very useful when dealing with sequences. For example, we could use it like this in a script:<br />
<code language="python"><br />
#Script to process a Social Security Number</code></p>
<p><code language="python">ssn = ""</code></p>
<p><code language="python">while not ssn:     #Empty strings evaluate to false.</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;ssn = raw_input("Enter your Social Security Number: ")</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;ssn = ssn.replace("-", "") #Eliminate the dashes, if present.</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;if len(ssn) != 9:     #Checks the number of digits.</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "This is an invalid number."</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print "Try again please."</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ssn = "" &nbsp;&nbsp;&nbsp;&nbsp;#Set ssn to false</code></p>
<p><code language="python">print "Your Social Security Number is: " + ssn<br />
</code><br />
On this example, we created a while loop that continues to loop until a Social Security Number of nine digits is entered.</p>
<p>Another common function is the range function. This function is used to create a list of successively higher numbers. It&#8217;s most common use is in conjunction with for loops, allowing us to repeat a block of statements a certain number of times. It can take up to three parameters. Here is what it does:<br />
<code language="python"><br />
&gt;&gt;&gt; range(5)     #One parameter, returns list of numbers from 0 to n-1.</code></p>
<p><code language="python">[0, 1, 2, 3, 4]</code></p>
<p><code language="python">&gt;&gt;&gt; range(2, 5)     #First parameter is lower bound.</code></p>
<p><code language="python">[2, 3, 4]</code></p>
<p><code language="python">&gt;&gt;&gt; range(0, 10, 2)     #Third parameter provides a step.</code></p>
<p><code language="python">[0, 2, 4, 6, 8]<br />
</code><br />
To use this in a for loop you can do something like:<br />
<code language="python"><br />
def doit():</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;print "Done it."</code></p>
<p><code language="python">num=int(raw_input("How many times do you want to do this? "))</code></p>
<p><code language="python">for i in range(num):</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;doit()<br />
</code><br />
This little script will simply execute the doit function however many times the user requests. So, if we execute it from the command line, it will look something like:<br />
<code language="python"><br />
/home/me/MyDocs&gt; python test.py</code></p>
<p><code language="python">How many times do you want to do this? 4</code></p>
<p><code language="python">Done it.</code></p>
<p><code language="python">Done it.</code></p>
<p><code language="python">Done it.</code></p>
<p><code language="python">Done it.<br />
</code><br />
As we have seen already there are times in which Python will complain if a certain input it receives is not of the correct type. For example, the range function accepts only integers as input. The raw_input function returns its input as a string, that is why we use the int function to try to convert its output into an integer.</p>
<p>The last function we are going to look at is the type function. All it does is return the type of its input. For example:<br />
<code language="python">&gt;&gt;&gt; type(5)</code><br />
<code language="python">&#60;type 'int'&#62;<br />
</code></p>
<p><code language="python">&gt;&gt;&gt; type('5')</code><br />
<code language="python">&#60;type 'string'&#62;<br />
</code></p>
<p>So we could use it, for example when we want to make sure that a certain object we are about to do something to is of the correct type. For example, let&#8217;s say that we wanted to write a function that displays the methods available to a certain object. Let&#8217;s first create a class with one variable and one method:<br />
<code language="python"><br />
&gt;&gt;&gt; class Obj:</code></p>
<p><code language="python">...     def __init__(self):     #This is a special method that runs when instances are created.</code></p>
<p><code language="python">...         self.data = 1     #In this case it just initializes a variable to 1</code></p>
<p><code language="python">...     def add(self, num):     #This is a method that will be available to our instances.</code></p>
<p><code language="python">...          self.data = self.data + num<br />
</code><br />
Now, let&#8217;s create an instance object based on this class:<br />
<code language="python"><br />
&gt;&gt;&gt; ob = Obj()</code></p>
<p><code language="python">&gt;&gt;&gt; ob.data</code></p>
<p><code language="python">1</code></p>
<p><code language="python">&gt;&gt;&gt; ob.add(2)</code></p>
<p><code language="python">&gt;&gt;&gt; ob.data</code></p>
<p><code language="python">3</code></p>
<p><code language="python">&gt;&gt;&gt; dir(ob)</code></p>
<p><code language="python">['data']</code></p>
<p><code language="python">&gt;&gt;&gt; ob.__dict__</code></p>
<p><code language="python">{'data': 3}<br />
</code><br />
As you can see, objects that we create ourselves, as opposed to the built-in objects, do not automatically display the methods they have at their disposal. (There is a not so hard way to make them do that, but we are not going to get into that.) So, now let&#8217;s create a function that lets us know what methods are available to our homemade objects.<br />
<code language="python"><br />
import types</code></p>
<p><code language="python">def find_methods(instance):</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;clss = instance.__class__ &nbsp;&nbsp;#We find the class object of the instance</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;methods = []</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;for name in dir(clss):     #Get the named items from the class object</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attribute = clss.__dict__[name] #Get the value of items from the __dict__</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if type(attribute) == types.FunctionType:     #is it a function</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;methods.append(attribute)</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;return methods<br />
</code><br />
Now, we can use this function to find the methods in our little object:<br />
<code language="python"><br />
&gt;&gt;&gt; find_methods(ob)</code></p>
<p><code language="python">[&#60;function __init__ at 007CCD7C&#62; , &#60;function add at 007CC87C&#62;]<br />
</code><br />
Note:<br />
In Python, classes can inherit methods and variables from one or more classes too. This is called multiple inheritance. Our function would have to be a little different to be able to read functions inherited from other classes.</p>
<p>Well as we said before, time is precious. So, why don&#8217;t we finish this part of the tutorial looking at the time module.</p>
<p><a name="Time"></a></p>
<h2>Time</h2>
<p>Computers perform time calculations in reference to an &#8220;epoch&#8221; (like a pivot date). In the Unix family of operating systems the &#8220;epoch&#8221; is January 1, 1970, 0 hours, 0 seconds, UTC. Python follows that same method of handling time. The time module has several functions that we can use to handle time related tasks. In its most basic form, Python expresses the current time as the number of seconds since the &#8220;epoch&#8221;. Here is how you do it:<br />
<code language="python"><br />
&gt;&gt;&gt; import time</code></p>
<p><code language="python">&gt;&gt;&gt; time.time()</code></p>
<p><code language="python">1006015080.406<br />
</code><br />
Not very easy to read. However, other functions allow us to manipulate this output with ease. For example the localtime function.<br />
<code language="python"><br />
&gt;&gt;&gt; time.localtime(time.time())</code></p>
<p><code language="python">(2001, 11, 17, 11, 40, 37, 5, 321, 0)<br />
</code><br />
The localtime function returns a tuple representing: Year, month, day, hour, minute, second, weekday (0-6), Julian day (1-366), and the daylight savings time flag (-1 (force disable), 0 (default), or 1 (force enable)). There are also many other functions in this module that you should become familiar with. But, even with just this two functions we can do something useful. Let&#8217;s create a little timer class that we can use to check the time when a certain event in a program takes place and to time how long it takes our program to do its tasks. (Remember that you have to include an import time statement somewhere for this to work).<br />
<code language="python"><br />
class Timer:</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;def __init__(self):<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.start_time = time.time()</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;def cur_time(self):</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;now = time.time()</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tt=time.localtime(now)</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if tt[3] &gt; 12:</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr = int(tt[3]) - 12</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ampm = 'p.m.'</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else:</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hr = int(tt[3])</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ampm = 'a.m.'</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ct = "%s:%s:%s %s %s/%s/%s" %(str(hr), tt[4], tt[5], ampm, tt[1], tt[2], tt[0])</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ct</code></p>
<p><code language="python">&nbsp;&nbsp;&nbsp;&nbsp;def elapsed(self):</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;now = time.time()</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minutes  =(now - self.start_time) / 60</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;secs = (now - self.start_time) % 60     #The remainder of the division</code><br />
<code language="python">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 'Elapsed: %s min %s sec' % (int(minutes), int(secs))<br />
</code><br />
If we save that into a file called timer.py we can then import it into any of our programs. Let&#8217;s import it into the Python Command Line to play with it a little.<br />
<code language="python"><br />
&gt;&gt;&gt; import timer</code></p>
<p><code language="python">&gt;&gt;&gt; mytimer = timer.Timer()<br />
</code><br />
As soon as the instance is created it records the time in the start_time variable. We can verify that like this:<br />
<code language="python"><br />
&gt;&gt;&gt; mytimer.start_time</code></p>
<p><code language="python">1006016982.671<br />
</code><br />
Now let&#8217;s check the current time.<br />
<code language="python"><br />
&gt;&gt;&gt; mytimer.cur_time()</code></p>
<p><code language="python">'12:10:49 a.m. 11/17/2001'<br />
</code><br />
And finally, check how much time has elapsed since the instance was created.<br />
<code language="python"><br />
&gt;&gt;&gt; mytimer.elapsed()</code></p>
<p><code language="python">'Elapsed: 1 min 38 sec'<br />
</code><br />
Well, that is it for this section. It didn&#8217;t take too much time now did it? <img src='http://www.themaemo.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>We are going to wrap up this part of the tutorial here.  The remaining parts of the tutorial will be quite interesting.  Hopefully it won&#8217;t be too long before they are completed.  Come back and check in a little while.  And remember that if you would like to contribute your help to this tutorial you are very welcome.  Just leave us a note and tell us how to contact you.  Happy coding to all.<img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=214&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/python-for-newbies-part-two/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Python for Newbies &#8211; Tutorial</title>
		<link>http://www.themaemo.com/python-for-newbies/</link>
		<comments>http://www.themaemo.com/python-for-newbies/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 16:23:24 +0000</pubDate>
		<dc:creator>rm42</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Editorial]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[maemo5]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[nokia n900]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=183</guid>
		<description><![CDATA[This is a Python tutorial that tries to touch on most areas of the Python language, but attempts to be very simple so that people who have never done any sort of programming can grasp it.  Special attention will be given to its use as a Maemo OS development platform.]]></description>
			<content:encoded><![CDATA[<a href='http://www.themaemo.com/python-for-newbies/' class='retweet vert' >Python for Newbies &#8211; Tutorial</a><div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fpython-for-newbies%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fpython-for-newbies%2F" height="61" width="51" /></a></div>
<p>This is a <a href="http://www.themaemo.com/tag/python/" target="_blank">Python</a> tutorial that tries to touch on most areas of the <a href="http://www.python.org">Python language</a>, but attempts to be very simple so that people who have never done any sort of programming can grasp it.  Special attention will be given to its use as a <a href="http://www.themaemo.com/tag/maemo/" target="_blank">Maemo OS </a>development platform.  The content of this tutorial is provided under the Creative Commons Attribution-Share Alike 3.0 license:</p>
<p><a href="http://creativecommons.org/licenses/by-sa/3.0/">http://creativecommons.org/licenses/by-sa/3.0/</a></p>
<p><a href="http://creativecommons.org/licenses/by-sa/3.0/legalcode">http://creativecommons.org/licenses/by-sa/3.0/legalcode</a></p>
<p>The versions of Python and other libraries targeted by the tutorial will be initially the ones available on <a href="http://www.themaemo.com/tag/maemo5/" target="_blank">Maemo 5</a> at the time of the <a href="http://www.themaemo.com/and-now-for-something-completely-different-the-n900-and-its-killer-feature/">N900</a> release. That means Python 2.5.4. As Maemo starts moving to more recent versions of Python we will attempt to keep this tutorial in sync.</p>
<p>If you have any other comments or suggestions please let me know.  We have a Google Wave available for those that would like to contribute to the content.</p>
<p>Due to its length, we have divided the tutorial in two parts (maybe three by the time we are done).  There are a few sections still missing at the end of the tutorial.  We hope to add them in the near future.  But, again, if someone would like to help, let us know.</p>
<h2>Table of Contents</h2>
<h3>Part One</h3>
<ul>
<li><a href="#What is Python">What is Python?</a></li>
<li><a href="#Why Python">Why Python?</a></li>
<li><a href="#Installing Python">Installing Python</a></li>
<li><a href="#How Python works">How Python works</a></li>
<li><a href="#The building blocks of a Python program">The building blocks of a Python program</a>
<ul>
<li><a href="#Variables">Variables</a></li>
<li><a href="#Expressions">Expressions</a></li>
<li><a href="#Numbers">Numbers</a></li>
<li><a href="#Strings">Strings</a></li>
<li><a href="#Lists">Lists</a></li>
<li><a href="#Tuples">Tuples</a></li>
<li><a href="#Dictionaries">Dictionaries</a></li>
</ul>
</li>
<li><a href="#How to program in Python">How to program in Python</a>
<ul>
<li><a href="#for Loops">&#8220;for&#8221; loops</a></li>
<li><a href="#truth Tests">&#8220;truth&#8221; tests</a></li>
<li><a href="#while Loops">&#8220;while&#8221; Loops</a></li>
<li><a href="#if Statements">&#8220;if&#8221; statements</a></li>
</ul>
</li>
<h3><a href="http://www.themaemo.com/python-for-newbies-part-two/">Part Two</a></h3>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Functions">Functions</a>
<ul>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Defining a function">Defining a function</a></li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Namespaces and Scope">Namespaces and Scope</a></li>
</ul>
</li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Modules">Modules</a></li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Working with files">Working with files</a></li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Classes and Objects">Classes and Objects</a></li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Errors and Error Handling">Errors and Error Handling</a></li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Other common built-in functions">Other common built-in functions</a></li>
<li><a href="http://www.themaemo.com/python-for-newbies-part-two/#Time">Time</a></li>
<h3><span id="more-183"></span></h3>
<h3>Part Three</h3>
<li>GUI &#8211; Qt development</li>
<li>GUI &#8211; GTK development</li>
<li>Maemo/N900 specific modules</li>
<li>Bibliography (attributions)</li>
</ul>
<p><a name="What is Python"></a></p>
<h2>What is Python?</h2>
<p>Python is a computer programming language created initially by Guido Van Rossum, who released it to the world as an “Open Source” “Free”program. It has since then been progressively improved by the contributions of hundreds of computer programmers around the world. The Python package can be downloaded gratis from the internet for every major computing platform in existence. It can be used and even modified for just about any purpose.</p>
<p><a name="Why Python"></a></p>
<h2>Why Python?</h2>
<p>There are many computer programming languages in existence. They all have different advantages and disadvantages. The brain of a computer is its processor. No processor understands English. The processor needs to receive input in a format that it understands. Most processors are made to understand commands formatted as a series of zeros “0” and ones “1”. This format is called binary. It is possible to write programs by hand using this format of zeros and ones, but it is very difficult, time consuming, and error prone. That is why computer programming languages have been invented.</p>
<p>Programming languages are frequently categorized as “low level” or “high level”. Low level languages were the first ones to appear. They simplified the process of writing instructions to the computer by allowing the use of normal words to be used in writing the program. A translator program, a “compiler”, translates the program’s instructions into a binary file that can then be understood by the processor. However, low level programming languages are still quite difficult to master. They force the programmer to understand the way the computer works internally. The programmer has to give instructions for every step that the computer must take to handle a certain task, which can easily lead to errors and serious problems. On the other hand, low level programs tend to be quite fast and efficient (if done correctly).</p>
<p>High level languages are designed to make it easier to program on. The instructions look more like normal language. And, a lot of the details are handled by the compiler. This makes for much shorter development time, but can also mean that the program is not as fast and efficient as a program would be if done in a lower level programming language.</p>
<p>Python is a very high level programming language. Many consider it the easiest programming language to learn and to program on. Many common tasks that would normally have to be programmed by the programmer are already built in to the language. Python is very useful as an easy and quick way to program anything from small little scripts to large scale client/server systems. This is especially true with today’s ultra fast computers that make up for the speed disadvantage inherent to high level programming languages. Programmers tend to like Python because of its clean and logical syntax, which shortens development cycles tremendously. It also forces programmers to use code indentation correctly. At first, some programmers see this as a challenge and unnecessary restriction. However, not long after beginning to use it, most programmers realize that it is easy to adjust to it and that it results in very clean code which is easily maintained (even if the code was written by someone else).</p>
<p><a name="Installing Python"></a></p>
<h2>Installing Python</h2>
<p>To install Python on the <a href="http://www.themaemo.com/tag/n900/" target="_blank">N900</a>, just install an aplication that uses Python. For example, pyGTKeditor and/or (any one knows of a good PyQt app for Maemo?).</p>
<p>If you are using Linux, Python should already be installed. On Windows, just go to www.python.org/download/ and get yourself a download of Python 2.6.4, not the latest 3.x, since Python 3.x code is not compatible with the one on the N900. (It is really not too different, but different enough to break things.)</p>
<p><a name="How Python works"></a></p>
<h2>How Python works</h2>
<p>Python programs run with the aid of an “interpreter”. The interpreter is a program that converts the code into the binary instructions needed by the processor, at run time. There is an interpreter for each different platform where Python runs. This allows Python code written in a Windows machine, to run unchanged, in a Linux machine, a Macintosh machine, or even a smart phone. Of course, Python also has a lot of “platform specific” features that are optimized for the platform for which they are written. (Avoid these if you don’t want to tie your program down to a specific platform.) The interpreter must, either be installed on the computer that needs to run the Python program, or the Python program must be packaged in conjunction with the interpreter so that it can be run by computers without Python.</p>
<p>The interpreter can be run directly in what is called the “Interactive Command Line”. Python commands can be typed directly into this session and they are processed immediately showing the results of the command. This unique feature allows for quick and easy testing of ideas and code.</p>
<p>Most Python programs, however, are written with some type of text editor, saved as plain text files with a .py extension, and run as an independent process. Since there is no need to “compile” a Python program before running it, a programmer can test its changes to the code immediately after saving them.</p>
<p><a name="The building blocks of a Python program"></a></p>
<h2>The building blocks of a Python program</h2>
<p>First of all, what is a “program”? Well, “a program is a sequence of instructions that specifies how to perform a computation.” *i</p>
<p>Enter Python&#8217;s interactive mode ( On the N900, open the Terminal application and enter the following command: python), and let&#8217;s do our first program as it is traditionally done:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; print &#34;Hello World&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">Hello World<br />
</span><br />
Here, the word “<span style="font-family: Courier New,monospace;">print</span>” is a built in command or &#8220;statement&#8221; that sends the given argument to the screen. The second part of the program, what follows the print statement, is the argument itself, in this case, the string “<span style="font-family: Courier New,monospace;">Hello World</span>”. The quote marks tell Python to treat the words inside of them as a string, rather than as a command or a variable. (A &#8220;string&#8221; is a sequence of characters, like a word, a sentence, etc. They are further explained latter in this section.)</p>
<p>Note:<br />
Typically, in Python manuals and tutorials, when showing python code entered in an interactive session the &gt;&gt;&gt; represents the Python Command Line prompt. When a compound statement is being defined (one that takes more than one line), Python switches to &#8216;&#8230;&#8217; as a prompt.</p>
<p>Note:<br />
Text typed after a # is referred to as a comment, and is ignored by the Python interpreter.</p>
<p><a name="Variables"></a></p>
<h3>Variables</h3>
<p>What is a variable? A variable is a name (a word) that refers to a certain value. We can use almost any word and assign a value to it. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hi = &#34;Hello World&#34;<br />
</span><br />
The word <span style="font-family: Courier New,monospace;">hi</span> is now the name of a variable who’s value is the string <span style="font-family: Courier New,monospace;">&#34;Hello World&#34;</span>. Let&#8217;s use the <span style="font-family: Courier New,monospace;">print</span> statement to send the value of <span style="font-family: Courier New,monospace;">hi</span> to the screen:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; print hi</span></p>
<p><span style="font-family: Courier New,monospace;">Hello World<br />
</span><br />
In Python, variables are very flexible. You don’t have to declare them first, like in other languages. You can assign any value to them, even if they already have a value of a different type. For example, let&#8217;s change the value of <span style="font-family: Courier New,monospace;">hi</span> to <span style="font-family: Courier New,monospace;">3.0</span>:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hi = 3.0</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; print hi</span></p>
<p><span style="font-family: Courier New,monospace;">3.0<br />
</span><br />
We can also assign a variable as the value of a variable. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; num = hi</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; print num</span></p>
<p><span style="font-family: Courier New,monospace;">3.0<br />
</span><br />
Another neat feature of Python’s interactive shell is that you don’t even have to use the print statement to see the values of variables and other objects. You can simply type their name and Python will display it.<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; num</span></p>
<p><span style="font-family: Courier New,monospace;">3.0<br />
</span><br />
<a name="Expressions"></a></p>
<h3>Expressions</h3>
<p>At the interactive command prompt one can type expressions and see their result interactively. “An expression is a combination of variables, operators and values that represents a single result value”i. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; num + 2</span></p>
<p><span style="font-family: Courier New,monospace;">5.0</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; ((5 &#8211; 1) + num) * 2</span></p>
<p><span style="font-family: Courier New,monospace;">14.0<br />
</span><br />
We can assign the value of an expression to a variable. Such as:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; numb = ((5 &#8211; 1) + num) * 2</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; numb</span></p>
<p><span style="font-family: Courier New,monospace;">14.0<br />
</span><br />
<a name="Numbers"></a></p>
<h3>Numbers</h3>
<p>Notice on this last example that the number returned by Python is a number with a decimal point. In computer terminology this is called a floating point number. Since the expression included a floating point number (3.0), the expression’s value was automatically converted into a floating point number. The reason for the distinction in number types is beyond the scope of this tutorial. In most computer programming languages, one has to be careful to use the right type of number for each application. In Python, it is good to know that there are different types of numbers, but Python will usually deal with the details quite well. The only caveat to currently watch out for is division. Notice this:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; 7 / 2</span></p>
<p><span style="font-family: Courier New,monospace;">3<br />
</span><br />
Since both numbers in the division are integers (a type of number without decimal places) Python performs an integer division. This may not be what someone new to programming expects. Currently, to work around this one can do things like this:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; 7.0 / 2     # or float(7) / 2</span></p>
<p><span style="font-family: Courier New,monospace;">3.5<br />
</span><br />
In more recent versions of Python (version 3.x), Python&#8217;s designers have decided to change the way this works so that it does what new users would expect. With the current version of Python in Maemo 5 one can already import this behavior from the &#8220;<span style="font-family: Courier New,monospace;">__future__</span>&#8221; module. We will see more about &#8216;importing&#8217; latter.</p>
<p>Some common operators associated with numbers are:</p>
<table border="1">
<tbody>
<tr>
<th>Operator</th>
<th>Description</th>
</tr>
<tr>
<td>+</td>
<td>Addition</td>
</tr>
<tr>
<td>-</td>
<td>Subtraction</td>
</tr>
<tr>
<td>*</td>
<td>Multiplication</td>
</tr>
<tr>
<td>/</td>
<td>Division</td>
</tr>
<tr>
<td>%</td>
<td>Remainder (e.g. 9%2=1; 8%2=0)</td>
</tr>
<tr>
<td>**</td>
<td>Power (4**2=16)</td>
</tr>
</tbody>
</table>
<p>There are also many math functions in Python for doing just about any operation needed. Here is a small sample (see the documentation for more). To access them you need to first import them from the math module, like this for example:<br />
<span style="font-family: Courier New,monospace;"><br />
from math import acos<br />
</span></p>
<table border="1">
<tbody>
<tr>
<th>Function</th>
<th>Description</th>
</tr>
<tr>
<td>acos(x)</td>
<td>Return the arc cosine of x</td>
</tr>
<tr>
<td>cos(x)</td>
<td>Return the cosine of x</td>
</tr>
<tr>
<td>log(x)</td>
<td>Return the natural logarithm of x</td>
</tr>
<tr>
<td>sqrt(x)</td>
<td>Return the square root of x</td>
</tr>
<tr>
<td>tanh(x)</td>
<td>Return the hyperbolic tangent of x</td>
</tr>
</tbody>
</table>
<p>A handy tip is that in the Interactive Command Prompt you can recall the last printed expression with the underscore character “_”. So for example, you can use Python as a handy calculator this way:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; 2 + 2</span></p>
<p><span style="font-family: Courier New,monospace;">4</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; _ + 6</span></p>
<p><span style="font-family: Courier New,monospace;">10<br />
</span><br />
There is also a special Python extension called Numerical Python (NumPy) which allows it to become a tool for higher math functions such as linear algebra and matrices. But, enough of numbers for now.</p>
<p><a name="Strings"></a></p>
<h3>Strings</h3>
<p>We already saw an example of a string in the “Hello World” example. “A string is an ordered collection of characters, used to store and represent text-based information”. Python strings can be enclosed in double, single, or even triple (for multi-line strings) quotes. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; &#39;Hello World&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello World&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#34;Hello &#39;Hello World&#39;&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#34;Hello &#39;Hello World&#39;&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#39;&#39;&#39;This is a longer string that spans</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230; several lines, doesn&#8217;t say anything</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230; meaningful, and ends here&#39;&#39;&#39;<br />
</span><br />
The fact that strings are “ordered” means that we can access their components by position. Each character in a string has an index position before it. For example the string “Python” has the following indexes:</p>
<div id="attachment_197" class="wp-caption alignnone" style="width: 559px"><img class="size-full wp-image-197" title="Ordered Strings" src="http://www.themaemo.com/wp-content/uploads/2009/12/Ordered-Strings.png" alt="String Indexes" width="549" height="98" />
<p class="wp-caption-text">String Indexes</p>
</div>
<p>Notice that the first character “P” is located at index 0, as in programming languages like C, not 1 as in languages like Basic. However, unlike C, with Python you can also use negative indexes, which start counting from the end of the string.</p>
<p>To get the characters located at certain indexes we can use their index number inside brackets. Let&#8217;s look at some examples.</p>
<p>To get the character located at the beginning of the string we can use:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; &#34;Python&#34;[0]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;P&#39;<br />
</span><br />
Or if we are using a variable:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw = &#34;Hello World&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[0]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;H&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[1]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;e&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[-1]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;d&#39;<br />
</span><br />
We can also get “slices” of a string by specifying the first and last index of the slice separated by a colon.<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw[1:7]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;ello W&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[4:-2]</span></p>
<p><span style="font-family: Courier New,monospace;">&#8216;o Wor&#8217;<br />
</span><br />
The left or right bounds of the string can be specified in a slice by leaving the index blank. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw[:5]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[6:]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;World&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[:]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello World&#39;<br />
</span><br />
Strings are very smart “objects”. They know how to behave correctly in many situations such as:</p>
<p>When adding a string to a string<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw + &#34; Today&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello World Today&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw[:5] + &#34; You&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello You&#39;<br />
</span><br />
Multiplication<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw[:6] * 5</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello Hello Hello Hello Hello &#39;<br />
</span><br />
Notice that in all the operations we have done so far with strings, the operation returns a result but the original string remains unchanged. That is how strings work. A string is what is called an “immutable sequence”. What this means is that to change a string we actually have to create a new string. For example:</p>
<p>Trying to change the value of a string character in place<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw[0] = &#34;M&#34;<br />
</span><br />
Raises an error!</p>
<p>However, since variables are so flexible we can simply assign a new value to it:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; hw= &#34;M&#34; + hw[1:]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; hw</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Mello World&#39;<br />
</span><br />
This works because the hw[1:] expression is calculated first, then “M” is added to it, and finally the result is assigned as the value of the variable hw.</p>
<p>Another way to join strings with variables is by means of string formatting. For example, what if you had a program that greets the user by name according to the time of day. For example, it could say something like: “Hi Joe. How are you this morning?”. In this case the program could gather the name of the user somehow and place it in a variable called “name”. It could also fetch the time of the day by looking at the computers clock, determine if it is morning, afternoon, or evening, and place the result in a variable called “time_of_day”. You could then have the following line in your program to merge them into a string:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; Greeting = &#34;Hi %s. How are you this %s&#34; % (name, time_of_day)<br />
</span><br />
Python replaces the occurrences %s with the respective variable in the tuple after the % character. (A &#8220;tuple&#8221; is a sequence of items inside a parentheses. Tuples are further explained latter in this book.) Here is another example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; dessert = &#34;Pecan Pie&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; max_per_person = 1</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; answer = &#34;The dessert of the day is %s. You can only take %i per person&#34; % (dessert, max_per_person)</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; answer</span></p>
<p><span style="font-family: Courier New,monospace;">&#34;The dessert of the day is Pecan Pie. You can only take 1 per person&#34;<br />
</span><br />
In this example we added a string variable and an integer variable into the <span style="font-family: Courier New,monospace;">answer</span> string. Strings and integers have different formatting codes (%s, %i). See Python&#8217;s documentation for other formatting codes.</p>
<p>Strings also have built-in methods such as the following:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; &#34;hello&#34;.capitalize()</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#34;HELLO&#34;.lower()</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;hello&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#39;hello&#39;.upper()</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;HELLO&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#39;Hello World&#39;.replace(&#34; &#34;, &#34;-&#34;)     #Replace occurrences of first parameter with second</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello-World&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#39; Hello World &#39;.lstrip()     #To strip the whitespace at the left of string</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello World &#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#39; Hello World &#39;.rstrip()     #To strip the whitespace at the right of string</span></p>
<p><span style="font-family: Courier New,monospace;">&#39; Hello World&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#39; Hello World &#39;.strip()     #To strip the whitespace at the left and right</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Hello World&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; &#34;This is a longer string&#34;.split()</span></p>
<p><span style="font-family: Courier New,monospace;">[&#39;This&#39;, &#39;is&#39;, &#39;a&#39;, &#39;longer&#39;, &#39;string&#39;]<br />
</span><br />
On the last example we see how the split method returns a list of strings. It separates the original string by some given delimiter. When none is given, the default, whitespace, is used. But, what is a list?</p>
<p><a name="Lists"></a></p>
<h3>Lists</h3>
<p>Like strings, lists are ordered sequences. So, they share many of the same functionality. However, lists are mutable sequences, that is we can change them in place. Also, unlike strings, lists can contain any type of object: numbers, strings, even other lists. Much of the simplicity, power, and popularity of Python comes from this built in object type.</p>
<p>To define a list, we simply have to enclose it in square brackets using commas as item delimiters:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L = [1, 2,&#39;three&#39;, 4]<br />
</span><br />
The L variable is now a list object. We can use indexes and slices to access its members:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L[0]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;1&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L[2:]</span></p>
<p><span style="font-family: Courier New,monospace;">[&#39;three&#39;, 4]<br />
</span><br />
And, as mentioned before, we can change them in place:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L[2] = 3</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L</span></p>
<p><span style="font-family: Courier New,monospace;">[1, 2, 3, 4]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L[0] = [&#39;one&#39;, &#39;two&#39;, &#39;three&#39;]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L</span></p>
<p><span style="font-family: Courier New,monospace;">[[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;], 2, 3, 4]<br />
</span><br />
We can also concatenate lists (add them together):<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L + [8, 9]</span></p>
<p><span style="font-family: Courier New,monospace;">[[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;], 2, 3, 4, 8, 9]<br />
</span><br />
And repeat or multiply:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; [1, 2, 3] * 3</span></p>
<p><span style="font-family: Courier New,monospace;">[1, 2, 3, 1, 2, 3, 1, 2, 3]<br />
</span><br />
We can delete items from lists using the del function:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L = [[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;], 2, 3, 4]</span></p>
<p><span style="font-family: Courier New,monospace;">del L[1]</span></p>
<p><span style="font-family: Courier New,monospace;">L</span></p>
<p><span style="font-family: Courier New,monospace;">[[&#39;one&#39;, &#39;two&#39;, &#39;three&#39;], 3, 4]<br />
</span><br />
Or even:<br />
<span style="font-family: Courier New,monospace;"><br />
del L[0][1]     #Deletes item at index 1 of L[0]</span></p>
<p><span style="font-family: Courier New,monospace;">L</span></p>
<p><span style="font-family: Courier New,monospace;">[[&#39;one&#39;, &#39;three&#39;], 3, 4]<br />
</span><br />
Lists can be sorted and reverse sorted:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L = [&#39;c&#39;, &#39;b&#39;, &#39;a&#39;, 1]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L.sort()</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L</span></p>
<p><span style="font-family: Courier New,monospace;">[1, &#39;a&#39;, &#39;b&#39;, &#39;c&#39;]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L.reverse()</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L</span></p>
<p><span style="font-family: Courier New,monospace;">[&#39;c&#39;, &#39;b&#39;, &#39;a&#39;, 1]<br />
</span><br />
Notice that the sort and reverse methods do not return a new sorted list as a result. They simply change the list in place and return a special value called None. To see the results of the sort we have to print the list.</p>
<p>Another little peculiarity to watch out for when using lists is the following:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L1 = [1, 2, 3]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L2 = L1</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L2</span></p>
<p><span style="font-family: Courier New,monospace;">[1, 2, 3]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L2[0] = 8</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L2</span></p>
<p><span style="font-family: Courier New,monospace;">[8, 2, 3]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; L1</span></p>
<p><span style="font-family: Courier New,monospace;">[8, 2, 3]<br />
</span><br />
Notice that changing an item in L2 also changed it in L1. The reason for this is that when we assign L1 as the value of L2 what Python actually does is assign a pointer to L1 as the value of L2. In other words, they are linked. If this is not the desired result, you can avoid it by doing the following:<br />
<span style="font-family: Courier New,monospace;"><br />
L2 = L1[:]<br />
</span><br />
Because slices return new lists, assigning a slice of all the items of L1 as the value of L2 results in L2 being a new, independent list, a clone of L1.</p>
<p>So as you can see lists are very easy and friendly to use. In Python lists have a very close relative. Let&#8217;s take a look at it now.</p>
<p><a name="Tuples"></a></p>
<h3>Tuples</h3>
<p>Tuples are very similar to lists. The difference (and the reason for their existence) is that tuples are immutable. In other words, they can not be changed in place. Other than that everything we saw about lists also applies to tuples.</p>
<p>Tuples are defined by parentheses:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; t = (1, 2, 3)</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; t[1]</span></p>
<p><span style="font-family: Courier New,monospace;">2</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; t[1:]</span></p>
<p><span style="font-family: Courier New,monospace;">(2, 3)<br />
</span><br />
Earlier we saw that strings know how to convert themselves to lists using their &#8217;split&#8217; method. We can also convert a string into a tuple with a function called <span style="font-family: Courier New,monospace;">tuple</span>. It works like this:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; tuple(&#39;some string&#39;)</span></p>
<p><span style="font-family: Courier New,monospace;">(&#39;s&#39;, &#39;o&#39;, &#39;m&#39;, &#39;e&#39;, &#39; &#39;, &#39;s&#39;, &#39;t&#39;, &#39;r&#39;, &#39;i&#39;, &#39;n&#39;, &#39;g&#39;)<br />
</span><br />
You may wonder when will you ever use tuples, since lists do everything tuples can do and more. Well, among other reasons, since tuples are immutable, they are handy whenever you want to make sure that they do not accidentally get changed by some call. Some built in operations require tuples. And last but not least, tuples make for excellent dictionary keys.</p>
<p><a name="Dictionaries"></a></p>
<h3>Dictionaries</h3>
<p>Dictionaries allow us to collect all kinds of objects just as lists and tuples do. However, rather than fetching them back through the use of index or offset location, dictionaries allow us to fetch their items by keys. So, for each item in a dictionary, there is an accompanying key. Here is a dictionary example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; d = {&#39;key1&#39;: &#39;dog&#39;, 2: &#39;cat&#39;, (&#39;key&#39;, &#39;number&#39;, &#39;three&#39;): &#39;mouse&#39;}<br />
</span><br />
As you can see, dictionaries are enclosed in curly brackets &#8216;{}&#8217;, and each key-value pair is separated by a colon &#8216;:&#8217;. Notice that we can use strings (<span style="font-family: Courier New,monospace;">&#39;key1&#39;</span>), numbers (<span style="font-family: Courier New,monospace;">2</span>), and tuples (<span style="font-family: Courier New,monospace;">(&#39;key&#39;, &#39;number&#39;, &#39;three&#39;)</span>) as dictionary keys. All of these are immutable type objects. Values can be anything we want: strings, lists, &#8230;, and even other dictionaries, which contain other dictionaries, that contain other&#8230;. Like lists, dictionaries can be modified in place. However, they are not ordered sequences so, as we said before, we can not use indexes or slices to retrieve their items. It is important to remember that the order in which dictionary items appear is not to be relied upon. Nevertheless, Python offers very simple ways to work with dictionaries. Let&#8217;s look at some examples.</p>
<p>Retrieving a value:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; d[&#39;key1&#39;]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;dog&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; d[2]</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;cat&#39;<br />
</span><br />
Changing the value of a key:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; d[&#39;key1&#39;] = [&#39;milk&#39;, &#39;cake&#39;]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; d</span></p>
<p><span style="font-family: Courier New,monospace;">{(&#39;key&#39;, &#39;number&#39;, &#39;three&#39;): &#39;mouse&#39;, 2: &#39;cat&#39;, &#39;key1&#39;: [&#39;milk&#39;, &#39;cake&#39;]}<br />
</span><br />
Notice that on the last example the order of the dictionary items is printed differently than how we entered it. Now let&#8217;s add a new entry:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; d[&#39;new&#39;] = 1.5</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; d</span></p>
<p><span style="font-family: Courier New,monospace;">{(&#39;key&#39;, &#39;number&#39;, &#39;three&#39;): &#39;mouse&#39;, 2: &#39;cat&#39;, &#39;key1&#39;: [&#39;milk&#39;, &#39;cake&#39;], &#39;new&#39;: 1.5}<br />
</span><br />
As with lists, to delete an item we can use the del function:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; del(d[(&#39;key&#39;, &#39;number&#39;, &#39;three&#39;)])</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; d</span></p>
<p><span style="font-family: Courier New,monospace;">{2: &#39;cat&#39;, &#39;key1&#39;: [&#39;milk&#39;, &#39;cake&#39;], &#39;new&#39;: 1.5}<br />
</span><br />
Two very important operations that are frequently needed is the ability to retrieve all the keys or all the values contained in a dictionary. Python does this easily:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; d.keys()</span></p>
<p><span style="font-family: Courier New,monospace;">[2, &#39;key1&#39;, &#39;new&#39;]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; d.values()</span></p>
<p><span style="font-family: Courier New,monospace;">[&#39;cat&#39;, [&#39;milk&#39;, &#39;cake&#39;], 1.5]<br />
</span><br />
Notice that in both instances Python returns a list of the items we requested. This is handy because we can then use any of the functions and methods associated with lists, such as sort and reverse, to arrange them in the order that we want. We could then iterate through each item in the right order, in spite of the fact that dictionaries are unordered collections. You may now wonder, what is to iterate? This brings us to our next major subject.</p>
<p><a name="How to program in Python"></a></p>
<h2>How to program in Python</h2>
<p>In this section we are going to see how we can use the different data and object types that we have already covered, as well as a few others, to put together full scale programs.</p>
<p>Up to now all we have done is review some of the main object types available in Python using quick little one line expressions that do a single operation. However, the real power of computer programming is its ability to have the computer do multiple things for us with one simple command on our part. The concept of iteration is a good example of this.</p>
<p>Iteration is “the process of repeating a set of instructions a specified number of times or until a specific result is achieved. For example if we had a list with five items and we wanted to print each one of them, we could manually type five lines of code that would print each item. But what if we did not know how many items the list contained at any particular time, or what if the list contained hundreds of items? Well, actually the solution is very simple. This is how we would do it in Python:</p>
<p><a name="for Loops"></a></p>
<h3>&#8220;for&#8221; Loops</h3>
<p>As we have seen already, lists can be of any length we desire. Lets see what we can do with a little list of 5 items.<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L = [1, 2, 3, 4, 5]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; for i in L:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print i</span></p>
<p><span style="font-family: Courier New,monospace;">1</span></p>
<p><span style="font-family: Courier New,monospace;">2</span></p>
<p><span style="font-family: Courier New,monospace;">3</span></p>
<p><span style="font-family: Courier New,monospace;">4</span></p>
<p><span style="font-family: Courier New,monospace;">5<br />
</span><br />
What we are doing is iterating through the list L, assigning a temporary variable named i (can be whatever you want) for each item in L, and printing it. Here is another example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; students = [&#39;John&#39;, &#39;Peter&#39;, &#39;Jeremy&#39;, &#39;Carly&#39;]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; for student in students:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;You are a very good student, %s. &#34; %(student)</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;</span></p>
<p><span style="font-family: Courier New,monospace;">You are a very good student, John.</span></p>
<p><span style="font-family: Courier New,monospace;">You are a very good student, Peter.</span></p>
<p><span style="font-family: Courier New,monospace;">You are a very good student, Jeremy.</span></p>
<p><span style="font-family: Courier New,monospace;">You are a very good student, Carly.<br />
</span><br />
This construct is called a for loop. It is the first compound statement that we look at. Notice that the first line, the header, of the loop terminates in a colon. Notice also that the second line of each of the two examples above, are indented. This is very important, as we will see later. The body of a for loop doesn’t have to be limited to one line. It can contain as many lines of commands as desired. It will execute all the commands of the body for each iteration, unless otherwise told in the code.</p>
<p>It is important to understand that the for loop is a sequence iterator. It can iterate through ordered sequence items, such as strings, lists, tuples, etc. This will carry you a long way in your programming needs. However, there is another way to iterate or repeat a series of commands. But before we see it, you need to understand another important concept.</p>
<p><a name="truth Tests"></a></p>
<h3>&#8220;truth&#8221; Tests</h3>
<p>In computer programming, certain expressions evaluate, to either truth or false. For example, we know that it is true that 5 is greater than 4. Python knows that too, and this is how Python expresses that:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; 5 &gt; 4</span></p>
<p><span style="font-family: Courier New,monospace;">1<br />
</span><br />
As you can see, the expression 5 &gt; 4 returned a value of 1. In programming, when evaluating the truthfulness of an expression, 1 is the common value for true and 0 is the common value for false. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; 4 == 5</span></p>
<p><span style="font-family: Courier New,monospace;">0<br />
</span><br />
On this example you can see that to evaluate the equality of two values we used two equal signs rather than one. This is because, as we saw earlier, one equal sign is the assignment operator. So remember to use two equal signs when evaluating equality. </p>
<p>Besides math operations, Python recognizes other expressions as either true or false. For example, empty data types, like an empty string, list, etc, evaluate to false. There are also many operators that can be used inside a truth test expression. See the Python documentation for these if you are interested.</p>
<p>You will understand truth tests better by seeing them in action. So, let&#8217;s dive into our second method of iteration.</p>
<p><a name="while Loops"></a></p>
<h3>&#8220;while&#8221; Loops</h3>
<p>A while loop repeats a set of commands until some terminating condition is met. They may never execute the body of the loop if the terminating condition is false to start with. Here is a basic example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; x = 1</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; while x &lt; 10:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print x,</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     x = x + 1</span></p>
<p><span style="font-family: Courier New,monospace;">1 2 3 4 5 6 7 8 9<br />
</span><br />
Here you can see that the condition that we test for is whether x is less than 10. This little loop will continue repeating itself until that condition is false. You may also notice that by adding a comma at the end of a print statement it does not print a new line character after each print. So, all the numbers are printed in the same line.</p>
<p>One important lesson to remember with while loops is that, unless you want the loop to run forever, you should be sure that the condition will eventually be false. Let&#8217;s just look at another simple example to solidify your understanding:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; s = &#39;Something&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; while s:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print s,</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     s = s[1:]     # Removes the first character of the string</span></p>
<p><span style="font-family: Courier New,monospace;">&#39;Something&#39; &#39;omething&#39; &#39;mething&#39; &#39;ething&#39; &#39;thing&#39; &#39;hing&#39;, &#39;ing&#39;, &#39;ng&#39;, &#39;g&#39;<br />
</span><br />
In this case, once the string is empty, the while loop stops because <span style="font-family: Courier New,monospace;">s</span> evaluates to false.</p>
<p>So, as we can see, without truth tests while loops would not be possible. However, there is an even more basic programming feature where truth tests play a key role. With it we will be able to start adding real intelligence to our programs.</p>
<p><a name="if Statements"></a></p>
<h3>&#8220;if&#8221; Statements</h3>
<p>The if statement allows our programs to select a course of action depending on whether or not a certain condition exists. The if statement is the third multi-line or compound statement that we look at. Let&#8217;s look at an example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; if 5 &gt; 4:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;Life is good&#34;<br />
</span><br />
As in the previous compound statements, if statements have a header. The header begins with the if word itself followed by the expression that is to be evaluated, and ends with a colon. Again the body of the statement is indented.</p>
<p>Let&#8217;s look at a more realistic example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; first_name = &#39;Bob&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; last_name = &#39;&#39;</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; Greeting = &#39;Hello %s %s&#39; % (first_name, last_name)</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; if first_name and last_name:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print Greeting<br />
</span><br />
In this example we can see that the Greeting would only be printed if both <span style="font-family: Courier New,monospace;">first_name</span> and <span style="font-family: Courier New,monospace;">last_name</span> evaluate to true. Since, in this case, last_name is an empty string it will evaluate to false, and the Greeting will not be printed. Python will simply continue to its next command outside of the body of the if statement. Let&#8217;s look at another example:<br />
<span style="font-family: Courier New,monospace;"><br />
age = int(raw_input(&#34;How old are you? &#34;))     #The int function returns its input as integer.</span></p>
<p><span style="font-family: Courier New,monospace;">gender = raw_input(&#34;Are you male or female? &#34;)</span></p>
<p><span style="font-family: Courier New,monospace;">if age &gt;= 13 and age &lt;= 19:</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;if gender.capitalize() == &#34;Male&#34;:</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &#34;You are a teenage boy.&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;else:</span></p>
<p><span style="font-family: Courier New,monospace;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print &#34;You are a teenage girl.&#34;<br />
</span><br />
The raw_input function allows us to get input from the user. If we type those commands in a file named test.py and ran it as a script from the Command Prompt (e.g.: ~\somedirectory&gt;python test.py) we would get the following output:<br />
<span style="font-family: Courier New,monospace;"><br />
How old are you? 15</span></p>
<p><span style="font-family: Courier New,monospace;">Are you male or female? Male</span></p>
<p><span style="font-family: Courier New,monospace;">You are a teenage boy.<br />
</span><br />
Here we can see that if statements can be nested inside other if statements. The same is true for any other compound statement. You can nest compound statements as deep as you like. In this example we also see that an else statement can be used in conjunction with an if statement. An if/else combination allows the program to decide between two courses of action. Only one of the two will be executed. A similar construct is the elif statement (which stands for “else if”) which allows the program to choose from any number of ways to proceed depending on which condition is found to match first. For example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; if day == &#34;Saturday&#34;:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;Happy day&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230; elif day == &#34;Sunday&#34;:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;Weekend is almost over.&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230; elif month != &#34;August&#34;:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;Today is not an August weekend&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230; elif hour &gt; 22:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;Time to go to bed&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230; else:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     print &#34;Today is not a weekend, it is August and I still have time to do something&#34;<br />
</span><br />
With if statements we can give our programs many options to select from. It will check each one in order and select the first one that returns a true evaluation. Notice that the “not equal” operator (!=) returns a true evaluation if the Month variable is anything other than “August”. Something to watch out for in this kind of construct is that the “Time to go to bed” string will not get printed even if it is past 10:00 p.m., unless all the previous options were false. And finally, notice that we ended the sequence of statements with an else block. This one will get executed for sure once all the previous options proved false.</p>
<p>So, as you can see, truth tests in conjunction with if/elif/else statements can be very powerful in helping you express the logic of your program. The if statement is very often found inside while and for loops to change the flow of operation of the loop or to exit the loop if a certain condition is found. Let&#8217;s look at an example:<br />
<span style="font-family: Courier New,monospace;"><br />
&gt;&gt;&gt; L = [&#34;mouse&#34;,&#34;&#34;, &#34;cat&#34;, &#34;dog&#34;, &#34;parrot&#34;]</span></p>
<p><span style="font-family: Courier New,monospace;">&gt;&gt;&gt; for animal in L:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     if animal == &#34;dog&#34;:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         print &#34;Dogs are not allowed&#34;</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         break</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     elif animal == &#34;&#34;:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         pass</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;     else:</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;         print &#34;What a nice %s you have&#34; %(animal)</span></p>
<p><span style="font-family: Courier New,monospace;">&#8230;</span></p>
<p><span style="font-family: Courier New,monospace;">What a nice mouse you have</span></p>
<p><span style="font-family: Courier New,monospace;">What a nice cat you have</span></p>
<p><span style="font-family: Courier New,monospace;">Dogs are not allowed<br />
</span><br />
The break statement is used to exit the current loop. If the loop of this example had been inside another loop, the break statement would have simply continued to the next iteration of the outer loop. The pass keyword simply tells Python to do nothing. Again, notice the all important use of indentation to correctly identify the end of nested statements.</p>
<p>What we have covered so far is enough for you to be able to write very rich and powerful programs. However, we have just touched the most basic elements of computer programming. There are a few more concepts to learn in order to take full advantage of what can be done in Python.  We will look at them in <a href="http://www.themaemo.com/python-for-newbies-part-two/">Python for Newbies &#8211; Part 2</a>.<img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=183&#038;type=feed" alt="" /></p>
<a href='http://www.themaemo.com/python-for-newbies/' class='retweet vert' >Python for Newbies &#8211; Tutorial</a>]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/python-for-newbies/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>HowTo: Launch a terminal app from a shortcut on Nokia N900</title>
		<link>http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut/</link>
		<comments>http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 07:27:31 +0000</pubDate>
		<dc:creator>archebyte</dc:creator>
				<category><![CDATA[Device]]></category>
		<category><![CDATA[Devices]]></category>
		<category><![CDATA[Hacks ,Tricks and Tips]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[n900 tips]]></category>
		<category><![CDATA[N900 Tricks]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[xterm]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut/</guid>
		<description><![CDATA[
On the N900, it is possible to run a terminal program like &#8216;top&#8217; directly from the Desktop/Shortcut. The following example creates a shortcut to launch the system monitior program &#8216;top&#8217;.
1. Use a text-editor like vi or Leafpad to create a file with the following text:

[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Terminal=true
Name=topx
Exec=/usr/bin/osso-xterm top
Icon=
X-Window-Icon=
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable

2. Save the file as topx.desktop.
3. As root, copy [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-launch-a-terminal-app-from-a-shortcut%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fhowto-launch-a-terminal-app-from-a-shortcut%2F" height="61" width="51" /></a></div>
<p>On the N900, it is possible to run a terminal program like &#8216;top&#8217; directly from the Desktop/Shortcut. The following example creates a shortcut to launch the system monitior program &#8216;top&#8217;.</p>
<p>1. Use a text-editor like vi or Leafpad to create a file with the following text:</p>
<pre>
[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Terminal=true
Name=topx
Exec=/usr/bin/osso-xterm top
Icon=
X-Window-Icon=
X-HildonDesk-ShowInToolbar=true
X-Osso-Type=application/x-executable
</pre>
<p>2. Save the file as topx.desktop.</p>
<p>3. As root, copy the file to the &#8216;/usr/share/applications/hildon/&#8217; directory. This will create an ugly blue application icon in the Application list called &#8216;topx&#8217;. </p>
<div style="text-align:center"><img src="http://www.themaemo.com/wp-content/uploads/2009/12/BmKervie.jpg" /></div>
<p>Launching &#8216;topx&#8217; will execute &#8216;top&#8217; directly in xterm. You may now put a shortcut on the desktop for quick access. The not-so-great part of this desktop-shortcut is that it displays the default icon.</p>
<p><img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=181&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/howto-launch-a-terminal-app-from-a-shortcut/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Nokia N900 Showing it can function on Portrait Mode &#8211; Pictures and Video</title>
		<link>http://www.themaemo.com/nokia-n900-showing-it-can-function-on-portrait-mode-pictures-and-video/</link>
		<comments>http://www.themaemo.com/nokia-n900-showing-it-can-function-on-portrait-mode-pictures-and-video/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 13:23:34 +0000</pubDate>
		<dc:creator>Satz</dc:creator>
				<category><![CDATA[Hacks ,Tricks and Tips]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Nokia N900]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[maemo]]></category>
		<category><![CDATA[maemo5]]></category>
		<category><![CDATA[n900]]></category>
		<category><![CDATA[N900-portrait]]></category>
		<category><![CDATA[nokia n900]]></category>
		<category><![CDATA[Nokia N900 portrait mode]]></category>

		<guid isPermaLink="false">http://www.themaemo.com/?p=170</guid>
		<description><![CDATA[
Now we have some interesting news for you all
Here are the pictures showing N900 can be used in portrait mode too, So it seems like they have already implemented and now taking their time to make it work flawless on accelerometer
It just matter of weeks to get the portrait mode working.








Here is the video
http://share.ovi.com/media/Guyver95.PortraitMode/Guyver95.10009?sort=0
Source
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.themaemo.com%2Fnokia-n900-showing-it-can-function-on-portrait-mode-pictures-and-video%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.themaemo.com%2Fnokia-n900-showing-it-can-function-on-portrait-mode-pictures-and-video%2F" height="61" width="51" /></a></div>
<p>Now we have some interesting news for you all</p>
<p>Here are the pictures showing N900 can be used in portrait mode too, So it seems like they have already implemented and now taking their time to make it work flawless on accelerometer</p>
<p>It just matter of weeks to get the portrait mode working.</p>
<p><img src="http://media.share.ovi.com/m1/s/1454/06228dc1a02c4e1f895d10454294e2ef.jpg" alt="Nokia N900 Showing it can function on Portrait Mode" /><span id="more-170"></span></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/fd6c9c0a4d4e4224b9b33489408b3b12.jpg" alt="Nokia N900 Showing it can function on Portrait Mode - Pictures and Video" /></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/f7e3e10a531843e58f803f827dc51135.jpg" alt="Nokia N900 Showing it can function on Portrait Mode - Pictures and Video" /></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/169668dc097546b89da3c133dc550fa7.jpg" alt="Nokia N900 Showing it can function on Portrait Mode - Pictures and Video" /></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/96fb1379afcc4eecbdac225b670f4a69.jpg" alt="" /></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/1abb415ac6e147cd8f44e2ca00a7a0bf.jpg" alt="Nokia N900 Showing it can function on Portrait Mode - Pictures and Video" /></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/ec11404ef2aa4c27be722dd3b2be96c2.jpg" alt="Nokia N900 Showing it can function on Portrait Mode - Pictures and Video" /></p>
<p><img src="http://media.share.ovi.com/m1/s/1454/b896191535ea48b1b5e3b341c0b52cc6.jpg" alt="Nokia N900 Showing it can function on Portrait Mode - Pictures and Video" /></p>
<p>Here is the video</p>
<p><a href="http://share.ovi.com/media/Guyver95.PortraitMode/Guyver95.10009?sort=0">http://share.ovi.com/media/Guyver95.PortraitMode/Guyver95.10009?sort=0</a></p>
<p><a href="http://share.ovi.com/media/Guyver95.PortraitMode/Guyver95.10002?sort=0">Source</a><img src="http://www.themaemo.com/?ak_action=api_record_view&#038;id=170&#038;type=feed" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.themaemo.com/nokia-n900-showing-it-can-function-on-portrait-mode-pictures-and-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
