<?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>Daten&#124;teiler &#187; Programmieren</title>
	<atom:link href="http://www.datenteiler.de/kategorie/programmieren/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.datenteiler.de</link>
	<description>Kopieren als Kulturtechnik</description>
	<lastBuildDate>Sat, 14 Jan 2012 14:39:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Tanz den Bubblesort</title>
		<link>http://www.datenteiler.de/tanz-den-bubblesort/</link>
		<comments>http://www.datenteiler.de/tanz-den-bubblesort/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 18:24:42 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=6275</guid>
		<description><![CDATA[Endlich habe ich mal verstanden, wie der Bubblesort funktioniert! Nicht schlecht was die Jungs und Mädels dort Vortanzen. Hier zum Beispiel der Tanz in Python implementiert, allerdings nur mit dem unsortierten Anfang, dem sortierten Ende und ohne das Ganze im Mittelteil: # Bubblesort in Python &#160; def bubblesort&#40;a&#41;: for j in range&#40;len&#40;a&#41; - 1&#41;: for [...]]]></description>
			<content:encoded><![CDATA[<p>Endlich habe ich mal verstanden, wie der Bubblesort funktioniert! Nicht schlecht was die Jungs und Mädels dort Vortanzen. Hier zum Beispiel der Tanz in Python implementiert, allerdings nur mit dem unsortierten Anfang, dem sortierten Ende und ohne das Ganze im Mittelteil:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Bubblesort in Python</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> bubblesort<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">for</span> j <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> - <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span> - j - <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">if</span> a<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> <span style="color: #66cc66;">&gt;</span> a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>:
                tmp = a<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span>
                a<span style="color: black;">&#91;</span>i<span style="color: black;">&#93;</span> = a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
                a<span style="color: black;">&#91;</span>i+<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span> = tmp
    <span style="color: #ff7700;font-weight:bold;">return</span> a
&nbsp;
a = <span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span>, <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">1</span>, <span style="color: #ff4500;">8</span>, <span style="color: #ff4500;">7</span>, <span style="color: #ff4500;">2</span>, <span style="color: #ff4500;">5</span>, <span style="color: #ff4500;">4</span>, <span style="color: #ff4500;">6</span>, <span style="color: #ff4500;">9</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Unsortiert: &quot;</span>, a<span style="color: black;">&#41;</span>
&nbsp;
result = bubblesort<span style="color: black;">&#40;</span>a<span style="color: black;">&#41;</span>	
<span style="color: #ff7700;font-weight:bold;">print</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Sortiert  : &quot;</span>, result<span style="color: black;">&#41;</span></pre></div></div>

<p>Ich hoffe nur, dass ich die Musik auch wieder aus meinem Kopf bekomme. ;-)</p>
<p><object style="height: 390px; width: 640px"><param name="movie" value="http://www.youtube.com/v/lyZQPjUT5B4?version=3"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/lyZQPjUT5B4?version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="540" height="390"></object></p>
<p>[via <a href="http://www.zipfelmaus.com">zipfelmaus.com</a>]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/tanz-den-bubblesort/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows Scripting mit Notepad++</title>
		<link>http://www.datenteiler.de/windows-scripting-mit-notepad/</link>
		<comments>http://www.datenteiler.de/windows-scripting-mit-notepad/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 20:40:03 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=5047</guid>
		<description><![CDATA[Damit das Skripten auch unter Windows Spaß macht benötigt man einen komfortablen Editor. Für das Entwickeln mit dem Windows Script Host (WSH) lässt einen Microsoft in diesem Punkt allerdings ganz schön im Regen stehen: Denn es gibt keinen WSH-Scripteditor aus Redmond. Mit PrimalScript und SystemScripter gibt es zwar gute von Drittanbietern für bspw. Visual Basic [...]]]></description>
			<content:encoded><![CDATA[<p>Damit das Skripten auch unter Windows Spaß macht benötigt man einen komfortablen Editor. Für das Entwickeln mit dem <a href="http://de.wikipedia.org/wiki/Windows_Script_Host">Windows Script Host (WSH)</a> lässt einen Microsoft in diesem Punkt allerdings ganz schön im Regen stehen: Denn es gibt keinen WSH-Scripteditor aus Redmond. Mit <a href="http://www.kessler.de/prd/sapien/primalscript.htm">PrimalScript </a> und <a href="http://www.scriptinternals.de/new/ger/home/default.htm">SystemScripter</a> gibt es zwar gute von Drittanbietern für bspw. Visual Basic Script (kurz: VBScript oder VBS), eine der Sprachen für den Windows Script Host, sie sind allerdings nicht Open Source. Jetzt sollte man aber aus Verzweiflung nicht damit anfangen, mit dem Windows-Standardeditor Notepad Skripte zu schreiben. Schließlich hat Notepad nur den einen einzigen Vorteil, dass er bei jeder Windows-Installation dabei ist. Den Funktionsumfang kann man dagegen bestenfalls als sehr bescheiden bezeichnen, da er sich auf &#8220;Suchen und Ersetzen&#8221; und automatischen Zeilenumbruch beschränkt. Diese Lücke füllt <a href="http://notepad-plus-plus.org/">Notepad++</a>, der kann viele Dateien gleichzeitig geöffnet halten, Sitzungen speichern, in Text mit regulären Ausdrücken suchen und ersetzen, was sich nicht nur auf gerade geöffnete Dateien beschränkt, Syntax-Highlighting für viele verschiedene Sprachen und vieles mehr. Außerdem steht er unter der freien GNU General Public License (GPL) und ist somit Freie Software. Sollte noch etwas fehlen, ist der Editor durch Plugins oder durch das Bearbeiten der Konfigurationsdateien die im XML-Format vorliegen erweiterbar.</p>
<p><span id="more-5047"></span></p>
<p><strong>Skripte aus Notepad++ direkt ausführen</strong></p>
<p>Wenn man mit Notepad++ VBScripte für den WSH erstellt, ist es praktisch, wenn man die Skripte auch gleich aus Notepad++ heraus ausführen kann, so wie bei einer einfachen IDE. Dazu muss man die Datei <code>shortcuts.xml</code> bearbeiten, die unter <code>C:\Dokumente und Einstellungen\USER\Anwendungsdaten\Notepad++</code> liegt. USER muss man aber durch den<br />
eigenen Benutzernamen ersetzen. Wenn man die Datei bearbeitet, sollte Notepad++ geschlossen sein, damit die Änderungen beim Schließen von Notepad++ nicht wieder überschrieben wird. Zum Editieren nimmt man in diesem Fall den Windows-Standardeditor Notepad und fügt folgende Zeile ein:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Command</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Run with WScript&quot;</span> <span style="color: #000066;">Ctrl</span>=<span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">Alt</span>=<span style="color: #ff0000;">&quot;no&quot;</span> <span style="color: #000066;">Shift</span>=<span style="color: #ff0000;">&quot;no&quot;</span> <span style="color: #000066;">Key</span>=<span style="color: #ff0000;">&quot;116&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>%windir%\system32\wscript.exe <span style="color: #ddbb00;">&amp;quot;</span>$(FULL_CURRENT_PATH)<span style="color: #ddbb00;">&amp;quot;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Command<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Startet man danach wieder Notepad++ erscheint der Eintrag &#8220;Run with WScript&#8221; unter dem Menüpunkt &#8220;Ausführen&#8221;, oder man startet das VBScript mit der Tastenkombination &#8220;Strg + F5&#8243;. Die Umgebungsvariable <code>%windir%</code> zeigt dabei auf den Pfad der Windows-Installation, was <code>C:\WINXP</code>, <code>C:\WINDOWS</code>, <code>C:\WINNT</code> oder ähnliches sein kann, wo unter <code>system32</code> die Datei <code>wscript.exe</code> liegen sollte.</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/02/wsh-notepad++.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/02/wsh-notepad++-300x199.png" alt="" title="wsh-notepad++" width="300" height="199" class="aligncenter size-medium wp-image-5077" /></a></p>
<p>Was man im Screenshot sehen soll ist, dass das aktuelle Skript ausgeführt wird, wenn man die Tastenkombination &#8220;Strg + F5&#8243; drückt. Das Skript stammt übrigens aus dem Buch <a href="http://www.amazon.de/gp/product/3827329108?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3827329108">Windows Scripting lernen</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3827329108" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> von Holger Schwichtenberg.</p>
<p>Genau genommen besteht WSH aus zwei Skripting Hosts, nämlich WScript und CScript. Im Befehlsumfang sind beide nahezu identisch, sie unterscheiden sich allerdings darin, wohin die Ausgabe geht. Bei WScript erfolgt die Ausführung als Windows-Anwendung, weshalb jede Ausgabe von <code>WScript.Echo</code> in einem Dialogfenster erscheint. Bei vielen Ausgaben kann das recht umständlich sein, weil man jedes Dialogfenster einzeln bestätigen muss, und das Skript dabei jedes Mal anhält. Bei CScript erfolgt die Ausführung von <code>WScript.Echo</code> dagegen in der Kommandozeile, wenn man nicht eine Ausgabemethode benutzt, die zur jeweiligen Sprache gehört, wie z.B. <code>MsgBox()</code> in VBScript. Um das eigene Skript aus Notepad++ heraus mit CScript zu testen, fügt man in <code>shortcuts.xml</code> noch folgende Zeile mit dem Standardeditor ein:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Command</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Run with CScript&quot;</span> <span style="color: #000066;">Ctrl</span>=<span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">Alt</span>=<span style="color: #ff0000;">&quot;no&quot;</span> <span style="color: #000066;">Shift</span>=<span style="color: #ff0000;">&quot;yes&quot;</span> <span style="color: #000066;">Key</span>=<span style="color: #ff0000;">&quot;116&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>cmd /K %windir%\system32\cscript.exe <span style="color: #ddbb00;">&amp;quot;</span>$(FULL_CURRENT_PATH)<span style="color: #ddbb00;">&amp;quot;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Command<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Damit die Kommandozeile nicht gleich wieder schließt, wenn das Skript beendet ist, sollte man sie mit <code>cmd /K</code> am besten gleich direkt öffnen, um dann das Skript darin laufen zu lassen. Ansonsten ist die Code-Zeile der übrigen recht ähnlich.</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/02/wsh-mit-notepad++.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/02/wsh-mit-notepad++-300x202.png" alt="" title="wsh-mit-notepad++" width="300" height="202" class="aligncenter size-medium wp-image-5089" /></a></p>
<p>Das Skript kann jetzt mit der Tastenkombination &#8220;Strg + Shift + F5&#8243; in der Kommandozeile aus Notepad++ heraus aufgerufen werden.</p>
<p><strong>Autovervollständigung aktivieren</strong></p>
<p>Seit der Version 5.0 kann Notepad++ auch Autovervollständigung, die aber standardmäßig deaktiviert ist. Um sie zu aktivieren, klickt man im Menü auf &#8220;Einstellungen&#8221;, &#8220;Optionen&#8221; und aktiviert dann im Reiter &#8220;Sicherheitskopie/Autovervollständigung&#8221; die Autovervollständigung mit einem Häkchen. Wenn man mag, kann man auch Funktionsparameter anhaken. </p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/02/Autovervollständigung-Notepad++.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/02/Autovervollständigung-Notepad++-300x170.png" alt="" title="Autovervollständigung-Notepad++" width="300" height="170" class="aligncenter size-medium wp-image-5101" /></a></p>
<p>Die Autovervollständigung gibt es leider nur für Visual Basic (VB) aber leider nicht für den Dialekt VBScript. Man kann aber die Datei <code>vb.xml</code> im Verzeichnis <code>C:\Programme\Notepad++\plugins\APIs</code> um die Elemente des Visual Basic Dialekts ergänzen:</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/02/vb.xml_.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/02/vb.xml_-300x173.png" alt="" title="vb.xml" width="300" height="173" class="aligncenter size-medium wp-image-5115" /></a></p>
<p>Nach einem Neustart von Notepad++ kann man dann die Autovervollständigung mit den neuen Elementen benutzen, vorausgesetzt unter Sprache ist &#8220;VB&#8221; voreingestellt.</p>
<p><a href="http://www.datenteiler.de/wp-content/uploads/2011/02/Autovervollständigung-Notepad++-VB.png"><img src="http://www.datenteiler.de/wp-content/uploads/2011/02/Autovervollständigung-Notepad++-VB-300x206.png" alt="" title="Autovervollständigung-Notepad++-VB" width="300" height="206" class="aligncenter size-medium wp-image-5120" /></a></p>
<p>Wenn man übrigens &#8220;Strg + Leertaste&#8221; drückt, hat man die komplette Liste der Autovervollständigung zu der jeweiligen Sprache.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/windows-scripting-mit-notepad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobiles Python III &#8211; ein simpler Vokabeltrainer</title>
		<link>http://www.datenteiler.de/mobiles-python-iii-ein-simpler-vokabeltrainer/</link>
		<comments>http://www.datenteiler.de/mobiles-python-iii-ein-simpler-vokabeltrainer/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:30:41 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.datenteiler.de/?p=3821</guid>
		<description><![CDATA[Mit Python auf einem Nokia-Handy mit S60-Plattform herumzuspielen, macht einfach Spaß. Außerdem kann man sich damit gut die Zeit vertreiben, wenn es an der Supermarktkasse wieder etwas länger dauert, oder man untätig in der Bahn sitzt. Vor gut 3 Jahren habe ich im ersten Teil beschrieben, wie man Python auf dem Handy installiert. Geändert hat [...]]]></description>
			<content:encoded><![CDATA[<p>Mit Python auf einem Nokia-Handy mit S60-Plattform herumzuspielen, macht einfach Spaß. Außerdem kann man sich damit gut die Zeit vertreiben, wenn es an der Supermarktkasse wieder etwas länger dauert, oder man untätig in der  Bahn sitzt. Vor gut 3 Jahren habe ich im <a href="http://www.datenteiler.de/mobiles-python/">ersten Teil</a> beschrieben, wie man Python auf dem Handy installiert. Geändert hat sich an der Installation seit damals nicht viel (s.u. &#8220;Exkurs: Installation von PyS60&#8243;), außer dass <em>Python for S60</em> mittlerweile in der Version 1.4.5 vorliegt, aber immer noch Python 2.2.2 verwendet wird, und ich mittlerweile ein <a href="http://www.amazon.de/gp/product/B001CZJHGU?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=B001CZJHGU">Nokia E71</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=B001CZJHGU" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> habe. Im <a href="http://www.datenteiler.de/mobiles-python-ii/">zweiten Teil</a> habe ich beschrieben, wie man die Bluetooth-Konsole unter Gnu/Linux einrichtet. Der Vorteil von der Bluetooth-Konsole ist, dass man in der Python-Shell seines Gnu/Linux-Rechners arbeitet und die Anweisungen per Funk an das Telefon weitergereicht und dort ausgeführt werden. Doch was nützt die schönste Spielerei, wenn man nicht ein kleines Projekt hat?</p>
<p><span id="more-3821"></span></p>
<p><strong>Die Voraussetzung</strong></p>
<p>Zur Zeit probiere ich etwas mit der relationalen Datenbank herum, die über das Modul <code>anydbm</code> eingebunden werden. Dabei ist <a href="http://docs.python.org/library/anydbm.html"><code>anydbm</code></a> nur eine Fassade, eine Schnittstelle zu verschiedenen Varianten von DBM-artigen Datenbanksystemen. Sollte dabei kein Datenbank-Modul verfügbar sein, wird das etwas langsame Modul <code>dumbdbm</code> benutzt. Bei PyS60 verbirgt sich hinter der Fassade das Modul <code><a href="http://wiki.forum.nokia.com/index.php/Database_in_PyS60">e32dbm</a></code>, welches man auch direkt laden könnte, allerdings auf Kosten der Plattformunabhängigkeit.</p>
<p>Ein Datenbankobjekt erzeugt man mit der Funktion <code>open()</code>, das man wie ein <a href="http://docs.python.org/tutorial/datastructures.html">Dictionary</a> verwenden kann, allerdings gibt es Einschränkungen:</p>
<ul>
<li>Schlüssel und zugeordneter Wert dürfen nur vom Typ <em>String</em> sein,</li>
<li>außerdem sind nur wenige Dictionary-Methoden wie <code>keys()</code>, <code>values()</code>, <code>iteritems()</code> verfügbar.</li>
</ul>
<p>Ein kleines Beispiel in der Python-Shell, um das Ganze zu veranschaulichen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">anydbm</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'c'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Mond'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'moon'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Sonne'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'sun'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Erde'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'earth'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Nachdem das Modul <code>anydbm</code> importiert ist, erzeugt man das Datenbankobjekt <em>db</em> und legt eine Datenbank mit dem Namen <em>test.db</em> auf der Speicherkarte im Verzeichnis <em>e:\</em> an. Das <em>c</em> bedeutet übrigens <em>create</em>; man erstellt eine neue Datenbank, anstatt eine bereits vorhandene zu öffnen. Möchte man eine existierende Datenbank zum Lesen und Schreiben öffnen, schreibt man ein <em>w</em> für <em>write</em> und nur zum Lesen ein <em>r</em> für <em>read</em>. Anschließend werden die Schlüsselpaare eingetragen, dabei muss der Schlüssel als String in eckigen Klammern stehen, der Wert kann einfach als String eingetragen werden. Dass es sich um Strings, also Zeichenketten handelt, zeigen die einfachen Anführungszeichen, welche die Inhalte umschließen. Zum Schluss wird der neue Inhalt gespeichert, indem die Datenbank mit der <em>close()</em>-Methode geschlossen wird. </p>
<p>Mit einer for-Schleife kann man nach schauen, ob die Einträge auch alle vorhanden sind. Vorher muss man die Datenbank wieder öffnen, dieses mal nur, um sie zu lesen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">for</span> key, value <span style="color: #ff7700;font-weight:bold;">in</span> db.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
...    <span style="color: #ff7700;font-weight:bold;">print</span> key, value
...
<span style="color: black;">Erde</span> earth
Mond moon
Sonne sun
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Um Schlüsselpaare der Datenbank hinzuzufügen, muss man sie im Lese- und Schreibmodus öffnen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Sterne'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'stars'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">for</span> key, value <span style="color: #ff7700;font-weight:bold;">in</span> db.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
...    <span style="color: #ff7700;font-weight:bold;">print</span> key, value
...
<span style="color: black;">Erde</span> earth
Mond moon
Sonne sun
Sterne stars
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Solange die Datenmenge noch überschaubar ist, wie in diesem Beispiel, kann man die Datenbank wie ein schönes praktisches Dictionary verwenden. Man sollte aber bedenken, dass es kein Dictionary ist. Schlüssel- und Wertepaare werden von <code>anydbm</code> nur im Bedarfsfall in den Hauptspeicher geladen. Sollte die Datenmenge auf so viele Einträge wachsen, dass sie vielleicht gar nicht mehr komplett in den Hauptspeicher des Telefons passt, sollte man folgende <a href="http://books.google.de/books?id=vfzazxfQScYC&#038;pg=PA483&#038;lpg=PA483&#038;dq=anydbm+python&#038;source=bl&#038;ots=8pN1GU6KZK&#038;sig=6bX1AjbDkM1-LD2Q12r3CeNKNH0&#038;hl=de&#038;ei=-5yFS-StG9TfsAaGyMlE&#038;sa=X&#038;oi=book_result&#038;ct=result&#038;resnum=2&#038;ved=0CAgQ6AEwAQ#v=onepage&#038;q=anydbm%20python&#038;f=false">&#8220;Todsünden&#8221;</a>, die Farid Hajji im <a href="http://www.amazon.de/gp/product/3827325439?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3827325439">Python-Praxisbuch</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3827325439" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> zusammenfasst, beim Arbeiten mit <code>anydbm</code> auf jeden Fall vermeiden: Statt der Dictionary-Methoden <code>keys()</code> und <code>items()</code>, die eine riesige Liste von Schlüsseln aus der Datenbank laden, die eventuell die Grenzen des Hauptspeichers sprengen würde, sollte man besser <code>iterkeys()</code> und <code>iteritems()</code> in einer Schleife aufrufen, damit Schlüssel- und Wertepaare auch weiter nur im Bedarfsfall in den Hauptspeicher geladen werden.</p>
<p>Das zeigt gleichzeitig den Nachteil von <code>anydbm</code>: Einträge können z.B. nur im Nachhinein sortiert werden, wenn  die gesamte Schlüsselliste in den Hauptspeicher geladen wurde:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> liste = db.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> liste.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> liste
<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Erde'</span>, <span style="color: #483d8b;">'Mond'</span>, <span style="color: #483d8b;">'Sonne'</span>, <span style="color: #483d8b;">'Sterne'</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Die Spielerei mit <code>anydbm</code> hat mich auf die Idee gebracht, einen kleinen Vokabeltrainer für <em>Python for S60</em> zu schreiben. Sicher, es gibt Programme wie <a href="http://code.google.com/p/pyask/downloads/list">pyAsk2</a>, allerdings wurde die letzte Aktualisierung am Code im April 2008 vorgenommen. Außerdem legt <em>pyAsk2</em> die Vokabeln in einer Textdatei ab, was Probleme mit Unicode-Zeichen nach sich zieht. Es klappt einfach nicht, Sonderzeichen wie Umlaute, spanische Buchstaben wie &ntilde; oder Buchstaben mit Akzent in die Textdatei zu schreiben, ohne dass dabei das ganze Programm abstürzt. Da gefällt mir eine Datenbanklösung mit <code>anydbm</code> bzw. <code>e32dbm</code> besser: So wie man die Wörter und Buchstaben hinein wirft, bekommt man sie auch wieder heraus:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Bär'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'bear'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'at sign @'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'At-Zeichen @'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'British pound £'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'Britisches Pfund £'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">for</span> key, value <span style="color: #ff7700;font-weight:bold;">in</span> db.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
...    <span style="color: #ff7700;font-weight:bold;">print</span> key, value
...
<span style="color: black;">British</span> pound £ Britisches Pfund £
Erde earth
Mond moon
at sign @ At-Zeichen @
Bär bear
Sonne sun
Sterne stars
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Mit der Anweisung <code>del</code> für Dictionaries kann man übrigens Schlüsselpaare leicht wieder entfernen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">del</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Bär'</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">del</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'at sign @'</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">del</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'British pound £'</span><span style="color: black;">&#93;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Ein weiterer Vorteil ist, dass man mit Hilfe der <code>split()</code>-Methode für Strings einen Datensatz in weitere Felder zerlegen kann, um z.B. weitere Informationen anzuhängen:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\t</span>est.db'</span>, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Erde'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'earth|the third planet in order of distance from the sun'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Sterne'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'stars|the fixed bodies in the sky, which are really distant suns'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Sonne'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'sun|the round body in the sky that gives light and heat to the earth'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> db<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Mond'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'moon|Spacemen landed on the moon'</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">for</span> key, value <span style="color: #ff7700;font-weight:bold;">in</span> db.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
...    <span style="color: black;">value</span>, definition=db<span style="color: black;">&#91;</span>key<span style="color: black;">&#93;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'|'</span><span style="color: black;">&#41;</span>
...    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'De: '</span>, key, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #483d8b;">'En: '</span>, value, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, <span style="color: #483d8b;">'    '</span>, definition, <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
... 
<span style="color: black;">De</span>:  Erde 
En:  earth 
     the third planet <span style="color: #ff7700;font-weight:bold;">in</span> order of distance <span style="color: #ff7700;font-weight:bold;">from</span> the sun 
...</pre></div></div>

<p>Das kann ja nicht nur eine Definition sein, wie in dem Beispiel, sonder auch ein Punktesystem, um einen Karteikasten abzubilden: Je höher die Punktezahl, desto weiter rutscht die Karte im Kasten nach hinten und wird weniger abgefragt. </p>
<p><strong>Zarte Anfänge</strong></p>
<p>Es folgt nun ein erster Entwurf des simplen Vokabeltrainers <code>smpltrainr.py</code>, wobei ich aber dazu sagen muss, dass ich noch nicht weit gekommen bin und auch noch nicht alle Ideen eingeflossen sind, die ich weiter oben besprochen habe:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">anydbm</span>, <span style="color: #dc143c;">os</span>
&nbsp;
path = <span style="color: #483d8b;">'e:<span style="color: #000099; font-weight: bold;">\\</span>dicts<span style="color: #000099; font-weight: bold;">\\</span>'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> dir_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; create dir of dict if it is not there &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #dc143c;">os</span>.<span style="color: black;">listdir</span><span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span>:
        <span style="color: #dc143c;">os</span>.<span style="color: black;">mkdir</span><span style="color: black;">&#40;</span>path<span style="color: black;">&#41;</span>  
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> open_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; open dict or create one &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">global</span> <span style="color: #008000;">dict</span>
    name = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Open dictionary: '</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #008000;">dict</span>=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>path + name, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span>:
        <span style="color: #008000;">dict</span>=<span style="color: #dc143c;">anydbm</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>path +name, <span style="color: #483d8b;">'c'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> write_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; write into dict &quot;&quot;&quot;</span>
    x = <span style="color: #483d8b;">' '</span>
    <span style="color: #ff7700;font-weight:bold;">while</span> x <span style="color: #66cc66;">!</span>= <span style="color: #483d8b;">'Q'</span>:
        word = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Word: '</span><span style="color: black;">&#41;</span>
        meaning = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Meaning: '</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">dict</span><span style="color: black;">&#91;</span>word<span style="color: black;">&#93;</span> = meaning
        x = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Press Q for quit? '</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> ask_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot; ask from dict &quot;&quot;&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> word, meaning <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">dict</span>.<span style="color: black;">iteritems</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
        ask = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span>word + <span style="color: #483d8b;">' means '</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> ask == meaning:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Correct'</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Wrong. '</span> + word + <span style="color: #483d8b;">' means '</span> + meaning 
&nbsp;
dir_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> 
open_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
x = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Do you want to (A)sk from or to (W)rite into the dictionary? '</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> x == <span style="color: #483d8b;">'W'</span>:
    write_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> x == <span style="color: #483d8b;">'A'</span>:
    ask_dict<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #008000;">dict</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Wie man sieht, findet die Interaktion zwischen User und Programm noch in der Python-Shell statt. Das wird natürlich noch durch das UI Framework <code>appuifw</code> ersetzt, damit für die Interaktion native GUI-Elemente wie in Symbian verwendet werden. Außerdem ist der Funktionsumfang des Programms auch noch sehr klein. Da werde ich aber noch weiter dran arbeiten.</p>
<p><strong><em>Exkurs:</em> Installation von PyS60</strong></p>
<p>Für die Installation auf einem Gerät mit der Plattform <em>S60 3rd Edition</em>, wie dem E71, benötigt man die Datei <a href="http://sourceforge.net/projects/pys60/files/pys60/1.4.5/PythonForS60_1_4_5_3rdEd.sis/download">PythonForS60_1_4_5_3rdEd.sis</a>, für die <em>2ed Edition</em> entsprechend <a href="http://sourceforge.net/projects/pys60/files/pys60/1.4.5/PythonForS60_1_4_5_2ndEd.SIS/download">PythonForS60_1_4_5_2ndEd.SIS</a> vom <a href="http://sourceforge.net/projects/pys60/files/">PyS60-Projekt</a>. Dazu ist die Datei <a href="http://sourceforge.net/projects/pys60/files/pys60/1.4.5/PythonScriptShell_1_4_5_3rdEd.SIS/download">PythonScriptShell_1_4_5_3rdEd.SIS</a> bzw. <a href="http://sourceforge.net/projects/pys60/files/pys60/1.4.5/PythonScriptShell_1_4_5_2ndEd.SIS/download">PythonScriptShell_1_4_5_2ndEd.SIS</a> noch ganz hilfreich, damit man zum Start einen Python-Shell mit Beispiel-Skripten zur Verfügung hat. Die Endung <em>.sis</em> zeigt bei Symbian übrigens immer an, dass die Datei noch auf dem Gerät installiert werden muss. Bei der Installation ist es wichtig, dass Python in den Telefonspeicher installiert wird, und nicht auf die Speicherkarte. Diese Shell benutze ich allerdings schon gar nicht mehr, sondern die in <a href="http://code.google.com/p/ped-s60/">Ped</a>. <em>Ped</em> ist eine sehr komfortable integrierte Entwicklungsumgebung (IDE) für Python auf Nokias S60-Plattform, mit der man Python-Code direkt im Telefon schreiben und, dank einer integrierten Python-Shell, auch ausführen kann.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/mobiles-python-iii-ein-simpler-vokabeltrainer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update: Meine IP-Adresse mit C/C++</title>
		<link>http://www.datenteiler.de/meine-ip-adresse-mit-cpp-herausfinden/</link>
		<comments>http://www.datenteiler.de/meine-ip-adresse-mit-cpp-herausfinden/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 22:44:32 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=1635</guid>
		<description><![CDATA[Laut dem WhatIsMyIP-Forum ist es sehr schwierig, seine eigene externe IP-Adresse mit einem C++-Programm herauszufinden. Dazu brauche man wenigstens 30 Zeilen Quellcode für den Socket, die Verbindung zum Server, die HTTP-Anfrage, das Abwarten der Antwort und so fort. Da ich das gerne glaube habe ich nicht wie in Perl oder Python ein eigenes kleines Programm [...]]]></description>
			<content:encoded><![CDATA[<p>Laut dem <a href="http://forum.whatismyip.com/f13/getting-external-ip-t194/forumdisplay.php?s=&#038;daysprune=&#038;f=34" target="_blank">WhatIsMyIP-Forum</a> ist es sehr schwierig, seine eigene externe IP-Adresse mit einem C++-Programm herauszufinden. Dazu brauche man wenigstens 30 Zeilen Quellcode für den Socket, die Verbindung zum Server, die HTTP-Anfrage, das Abwarten der Antwort und so fort. Da ich das gerne glaube habe ich nicht wie in <a href="http://www.imhorst.net/get-your-ip-address-with-perl/">Perl</a> oder <a href="http://www.imhorst.net/meine-ip-adresse-mit-python-herausfinden/">Python</a> ein eigenes kleines Programm bzw. eine eigene Funktion geschrieben, sonder auf die Funktion <code>system()</code> von C++ zurückgegriffen.</p>
<p>Mit <code>system()</code> kann man innerhalb eines C++-Programms ein anderes Programm ausführen. Hier zum Beispiel das Programm <em>Curl</em>, das bei den meisten Linux-Distributionen noch zusätzlich installiert werden muss. Bei Mac OS X ist es standardmäßig dabei. Hat man Curl installiert, kann man mit folgendem Programm seine externe IP-Adresse auf der Konsole anzeigen lassen:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;cstdlib&gt;</span>
&nbsp;
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
   <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">system</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;curl 'http://whatismyip.com/automation/n09230945NL.asp'&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #000080;">==</span><span style="color: #000040;">-</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span>
     <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Error executing Command&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #0000ff;">return</span>  <span style="color: #0000ff;">EXIT_SUCCESS</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Update:</strong><br />
Für die Programmiersprache C gibt es die Bibliothek <a href="http://curl.haxx.se/">libcurl</a>. Um sie zu nutzen habe ich die Version curl-7.19.4 <a href="http://curl.haxx.se/download.html">heruntergeladen</a> und mit dem berühmten Dreisatz <code>./configure &amp;&amp; make &amp;&amp; sudo make install</code> kompiliert. Alternativ kann man auch das Paket <code>libcurl3-dev</code> aus dem Repository seiner Distribution installieren: mit <em>Apt</em> geht das durch dir Eingabe von <code>apt-get install libcurl3-dev</code> im Terminal. Danach habe ich mir folgendes kleines Beispiel &#8220;zusammenkopiert&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/* myIP.c */</span>
<span style="color: #339900;">#include &lt;stdio.h&gt;</span>
<span style="color: #339900;">#include &lt;curl/curl.h&gt;</span>
<span style="color: #339900;">#include &lt;string.h&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
   CURL <span style="color: #000040;">*</span>curl<span style="color: #008080;">;</span>
   CURLcode res<span style="color: #008080;">;</span>
   <span style="color: #0000ff;">char</span> whatismyip<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">50</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
   <span style="color: #0000dd;">strcpy</span><span style="color: #008000;">&#40;</span>whatismyip, <span style="color: #FF0000;">&quot;whatismyip.com/automation/n09230945NL.asp&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
   curl <span style="color: #000080;">=</span> curl_easy_init<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span>curl<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
     curl_easy_setopt<span style="color: #008000;">&#40;</span>curl, CURLOPT_URL, whatismyip<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
     res <span style="color: #000080;">=</span> curl_easy_perform<span style="color: #008000;">&#40;</span>curl<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
     <span style="color: #ff0000; font-style: italic;">/* always cleanup */</span>
     curl_easy_cleanup<span style="color: #008000;">&#40;</span>curl<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #008000;">&#125;</span>
   <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Beim Kompilieren des Beispiels muss man noch das Attribut <code>-lcurl</code> anhängen, um die Fehlermeldungen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>ccufDDUa.o: In <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #000000; font-weight: bold;">`</span>main<span style="color: #ff0000;">':
simple.c:(.text+0x8a): undefined reference to `curl_easy_init'</span>
simple.c:<span style="color: #7a0874; font-weight: bold;">&#40;</span>.text+0xb4<span style="color: #7a0874; font-weight: bold;">&#41;</span>: undefined reference to <span style="color: #000000; font-weight: bold;">`</span>curl_easy_setopt<span style="color: #ff0000;">'
simple.c:(.text+0xbf): undefined reference to `curl_easy_perform'</span>
simple.c:<span style="color: #7a0874; font-weight: bold;">&#40;</span>.text+0xcd<span style="color: #7a0874; font-weight: bold;">&#41;</span>: undefined reference to <span style="color: #000000; font-weight: bold;">`</span>curl_easy_cleanup<span style="color: #ff0000;">'
collect2: ld gab 1 als Ende-Status zurück</span></pre></div></div>

<p>zu vermeiden. Eine weitere Fehlermeldung könnte die folgende sein:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>cc43idA6.o:<span style="color: #7a0874; font-weight: bold;">&#40;</span>.eh_frame+0x11<span style="color: #7a0874; font-weight: bold;">&#41;</span>: undefined reference to <span style="color: #000000; font-weight: bold;">`</span>__gxx_personality_v0<span style="color: #ff0000;">'
collect2: ld gab 1 als Ende-Status zurück</span></pre></div></div>

<p>Hier teilt der Linker mit, dass er zum Kompilieren noch die Option <code>-lstdc++</code> benötigt. Weitere Optionen für den Linker liefert das Kommando <code>curl-config --libs</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">gcc</span> <span style="color: #660033;">-o</span> myIP myIP.cpp <span style="color: #660033;">-lcurl</span> -lstdc++</pre></div></div>

<p>Wenn alles fehlerfrei funktioniert hat, gibt der Befehl <code>./myIP</code> im Terminal die eigene IP-Adresse zurück. Quellcode und Progamm kann man <a href="http://www.imhorst.net/wp-content/uploads/2009/02/myip.zip">hier herunterladen</a>.</p>
<p><strong>Bücher zu C++</strong></p>
<ul>
<li><a href="http://www.amazon.de/gp/product/3499600773?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3499600773">C++: Objektorientiertes Programmieren von Anfang an</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3499600773" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
<li><a href="http://www.amazon.de/gp/product/3836213850?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3836213850">Einstieg in C++</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3836213850" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/meine-ip-adresse-mit-cpp-herausfinden/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Die Funktion istZahl in C++</title>
		<link>http://www.datenteiler.de/die-funktion-istzahl-in-cpp/</link>
		<comments>http://www.datenteiler.de/die-funktion-istzahl-in-cpp/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 22:01:54 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=1711</guid>
		<description><![CDATA[Für ein kleines Programmierprojekt muss ich in C++ eine Eingabe überprüfen, ob wirklich nur ganze Zahlen, oder etwa andere Zeichen eingegeben wurden. Ich dachte da an dieses kleine Stück Quellcode: #include &#60;iostream&#62; using namespace std; &#160; int main&#40;&#41;&#123; &#160; int zahl = 0; char zeichen&#91;20&#93;; cout&#60;&#60;&#34;Bitte Zahl eingeben: &#34;; cin&#62;&#62;zeichen; &#160; while &#40;!&#40;sscanf&#40;zeichen, &#34;%d&#34;, &#38;zahl&#41;&#41;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Für ein kleines Programmierprojekt muss ich in C++ eine Eingabe überprüfen, ob wirklich nur ganze Zahlen, oder etwa andere Zeichen eingegeben wurden. Ich dachte da an dieses kleine Stück Quellcode:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
&nbsp;
        <span style="color: #0000ff;">int</span> zahl <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
        <span style="color: #0000ff;">char</span> zeichen<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Bitte Zahl eingeben: &quot;</span><span style="color: #008080;">;</span>
        <span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>zeichen<span style="color: #008080;">;</span>
&nbsp;
        <span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sscanf</span><span style="color: #008000;">&#40;</span>zeichen, <span style="color: #FF0000;">&quot;%d&quot;</span>, <span style="color: #000040;">&amp;</span>zahl<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Ungültige Eingabe. <span style="color: #000099; font-weight: bold;">\n</span>Bitte nur Zahlen eingeben: &quot;</span><span style="color: #008080;">;</span>
        	<span style="color: #0000dd;">cin</span><span style="color: #000080;">&gt;&gt;</span>zeichen<span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
            <span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>zahl<span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot; ist eine Zahl&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Nur leider zeigt dieser Code-Schnipsel bei größeren ganzen Zahlen nur noch die Zahl 2147483647 an, was genau dem obersten Wertebereich des Datentyps <em>int</em> entspricht. Eine Zahl die größer ist, kann das Programm nicht anzeigen:</p>
<div id="attachment_1716" class="wp-caption aligncenter" style="width: 534px"><a href="http://www.imhorst.net/wp-content/uploads/2009/02/istzahl1.png"><img src="http://www.imhorst.net/wp-content/uploads/2009/02/istzahl1.png" alt="&lt;em&gt;Diese Zahl kommt einem bekannt vor...&lt;/em&gt;" title="istzahl1" width="524" height="375" class="size-full wp-image-1716" /></a><p class="wp-caption-text"><em>Diese Zahl kommt einem bekannt vor...</em></p></div>
<p>Da ich aber mit Eingaben rechnen muss, die mehr als zehn Stellen haben können, hilft mir dieses Code-Beispiel nicht weiter. Daher habe ich eine eigene Funktion <code>istZahl()</code> geschrieben:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;cstring&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">int</span> istZahl<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> zahl<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">int</span> laenge<span style="color: #000080;">=</span><span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>zahl<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>laenge<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span> <span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span><span style="color: #008000;">&#41;</span>zahl<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;</span> <span style="color: #0000dd;">47</span> <span style="color: #000040;">&amp;&amp;</span> zahl<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;</span> <span style="color: #0000dd;">58</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">char</span> a<span style="color: #008000;">&#91;</span><span style="color: #0000dd;">20</span><span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Bitte eine Zahl eingeben: &quot;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cin</span>.<span style="color: #007788;">getline</span><span style="color: #008000;">&#40;</span>a,<span style="color: #0000dd;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>istZahl<span style="color: #008000;">&#40;</span>a<span style="color: #008000;">&#41;</span><span style="color: #000080;">==</span><span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Ungültige Eingabe. <span style="color: #000099; font-weight: bold;">\n</span>Bitte nur Zahlen eingeben: &quot;</span><span style="color: #008080;">;</span>
	<span style="color: #0000dd;">cin</span>.<span style="color: #007788;">getline</span><span style="color: #008000;">&#40;</span>a,<span style="color: #0000dd;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>a<span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; ist eine Zahl.&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Hier kann eine ganze Zahl mit bis zu 19 Stellen eingegeben werden, da die 20. Stelle für die Endekennung <em>\0</em> benötigt wird. Alle Stellen, die darüber hinausgehen, werden einfach abgeschnitten. Sollte das nicht reichen, kann man den Wert im Quellcode noch erhöhen.</p>
<p>So würde ich es machen, aber vielleicht gibt es ja noch schönere Lösungen?</p>
<p><strong>[Update]</strong> Wie man an den Kommentaren vielleicht schon sieht, geht die Funktion noch schöner und hat Dank <a href="http://home.arcor.de/hirnstrom" target="_blank">Stefan</a> den neuen Namen <em>istZiffer()</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;cstring&gt;</span>
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span>
<span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> MAX<span style="color: #000080;">=</span><span style="color: #0000dd;">5</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">bool</span> istZiffer<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">char</span> ziffer<span style="color: #008000;">&#91;</span>MAX<span style="color: #008000;">&#93;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">int</span> laenge<span style="color: #000080;">=</span><span style="color: #0000dd;">strlen</span><span style="color: #008000;">&#40;</span>ziffer<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i<span style="color: #000080;">=</span><span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i<span style="color: #000080;">&lt;</span>laenge<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span>
        <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>ziffer<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&gt;=</span> <span style="color: #FF0000;">'0'</span> <span style="color: #000040;">&amp;&amp;</span> ziffer<span style="color: #008000;">&#91;</span>i<span style="color: #008000;">&#93;</span> <span style="color: #000080;">&lt;=</span> <span style="color: #FF0000;">'9'</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span> 
        <span style="color: #666666;">// if (! isdigit (ziffer[i]))</span>
        <span style="color: #008000;">&#123;</span>
		<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
		<span style="color: #008000;">&#125;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span>
	<span style="color: #0000ff;">char</span> a<span style="color: #008000;">&#91;</span>MAX<span style="color: #008000;">&#93;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">do</span> 
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot;Bitte Ziffern eingeben: &quot;</span><span style="color: #008080;">;</span>
		<span style="color: #0000dd;">cin</span>.<span style="color: #007788;">getline</span><span style="color: #008000;">&#40;</span>a,MAX<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #008000;">&#125;</span><span style="color: #0000ff;">while</span> <span style="color: #008000;">&#40;</span>istZiffer<span style="color: #008000;">&#40;</span>a<span style="color: #008000;">&#41;</span><span style="color: #000080;">==</span><span style="color: #0000ff;">false</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000dd;">cout</span><span style="color: #000080;">&lt;&lt;</span>a<span style="color: #000080;">&lt;&lt;</span><span style="color: #FF0000;">&quot; ist eine Zahl.&quot;</span><span style="color: #000080;">&lt;&lt;</span>endl<span style="color: #008080;">;</span>
&nbsp;
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Das funktioniert soweit ganz gut, bis auf ein oder zwei Schönheitsfehler:</p>
<ol>
<li>Wenn ich im obigen Beispiel <em>istZiffer()</em> mehr als 4 Ziffern eingebe, wird alles was danach kommt einfach abgeschnitten, was aber für meine Bedürfnisse nicht weiter schlimm ist. </li>
<li>Gebe ich aber z.B. mehr als vier Buchstaben ein, habe ich einen nervigen Programmabbruch, den ich noch nicht ganz weg bekomme.</li>
<li>Wie <a href="http://www.deesasterorg/blog/" target="_blank">dee</a> schon sagt: Die Enter-Taste wird von der Funktion wie eine Ziffer behandelt, was ich auch noch ändern muss.</li>
</ol>
<p>Aber Dank der vielen guten Kommentare ist die Funktion schon viel besser geworden. ;-)</p>
<p><strong>Bücher zu C++</strong></p>
<ul>
<li><a href="http://www.amazon.de/gp/product/3499600773?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3499600773">C++: Objektorientiertes Programmieren von Anfang an</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3499600773" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
<li><a href="http://www.amazon.de/gp/product/3836213850?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3836213850">Einstieg in C++</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3836213850" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/die-funktion-istzahl-in-cpp/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Wie installiere ich MonoDevelop?</title>
		<link>http://www.datenteiler.de/wie-installiere-ich-monodevelop/</link>
		<comments>http://www.datenteiler.de/wie-installiere-ich-monodevelop/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 13:12:10 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Mono]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=1379</guid>
		<description><![CDATA[Keith Curtis hat in seinem Buch After The Software Wars ganz begeistert über C# berichtet, weshalb ich die Sprache unter Ubuntu 8.10 unbedingt einmal ausprobieren möchte. Da eine C#-Unterstützung erst für KDevelop 4 Zeit noch geplant ist, habe ich Mono und MonoDevelop installiert. Um mit C# unter Gnu/Linux Programme zu entwickeln, benutzt man am besten [...]]]></description>
			<content:encoded><![CDATA[<p>Keith Curtis hat in seinem Buch <a href="http://www.lulu.com/content/4964815" target="_blank">After The Software Wars</a> ganz begeistert über <a href="http://de.wikipedia.org/wiki/C_Sharp taregt="_blank"">C#</a> berichtet, weshalb ich die Sprache unter Ubuntu 8.10 unbedingt einmal ausprobieren möchte. Da eine <a href="http://www.kdedevelopers.org/node/3561" target="_blank">C#-Unterstützung erst für KDevelop 4 Zeit noch geplant</a> ist, habe ich <a href="http://de.wikipedia.org/wiki/Mono-Projekt" target="_blank">Mono</a> und <a href="http://de.wikipedia.org/wiki/MonoDevelop" target="_blank">MonoDevelop</a> installiert.</p>
<p><span id="more-1379"></span></p>
<p>Um mit C# unter Gnu/Linux Programme zu entwickeln, benutzt man am besten MonoDevelop als integrierte Entwicklungsumgebung (IDE) für Gnome. Außerdem braucht man noch die Mono .NET Laufzeitumgebung. Für Ubuntu 8.10 und Debian 5.0 empfiehlt sich daher eine umfangreiche Installation aller benötigten Pakete mit folgendem Befehl:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> mono-gmcs mono-gac mono-utils monodevelop
monodoc-browser monodevelop-nunit monodevelop-versioncontrol mono-xsp</pre></div></div>

<p>Anschließend findet man MonoDevelop im Gnome-Menü unter <strong>Anwendungen -> Entwicklung -> MonoDevelop</strong>.</p>
<p>Bei openSUSE 11.1 reicht es dagegen, einfach alle Pakete für MonoDevelop in YaST auszuwählen:</p>
<div id="attachment_1383" class="wp-caption alignleft" style="width: 310px"><a href="http://www.imhorst.net/wp-content/uploads/2009/01/monodevelop.png"><img src="http://www.imhorst.net/wp-content/uploads/2009/01/monodevelop-300x227.png" alt="MonoDevelop unter openSUSE 11 installieren." title="monodevelop" width="300" height="227" class="size-medium wp-image-1383" /></a><p class="wp-caption-text"><em>MonoDevelop mit YaST installieren.</em></p></div>
<p>Dummerweise fehlt bei <a href="http://packages.debian.org/sid/all/monodevelop/filelist" target="_blank">Debian</a> und <a href="http://packages.ubuntu.com/intrepid/all/monodevelop/filelist" target="_blank">Ubuntu &#8220;Intrepid Ibex&#8221;</a> genauso wie bei <a href="http://www.novell.com/products/linuxpackages/opensuse11.1/monodevelop.html" target="_blank">openSUSE 11.1</a> das <a href="http://anonsvn.mono-project.com/viewvc/trunk/monodevelop/main/po/de.po?view=log">deutsche Sprachpaket</a>. Aber da kann man abhelfen. Um das Sprachpaket zu installieren braucht man ersmal <a href="http://de.wikipedia.org/wiki/Gettext" target="_blank">GNU gettext</a>. Dann lädt man die Sprachdatei <a href="http://anonsvn.mono-project.com/viewvc/trunk/monodevelop/main/po/de.po?view=co">de.po</a> herunter und wandelt sie in eine binäre um:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">msgfmt</span> <span style="color: #660033;">-o</span> monodevelop.mo de.po</pre></div></div>

<p>Daraufhin erhält man die Datei <code>monodevelop.mo</code>, die man in den Ordner <code>/usr/share/locale/de/LC_MESSAGES/</code> kopiert:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> monodevelop.mo <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>locale<span style="color: #000000; font-weight: bold;">/</span>de<span style="color: #000000; font-weight: bold;">/</span>LC_MESSAGES<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Startet man anschließend MonoDevelop wieder, hat man die Menüs größtenteils auf Deutsch.</p>
<p><strong>Bücher über C# und Mono:</strong></p>
<ul>
<li><a href="http://www.amazon.de/gp/product/0321562992?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=0321562992">The C# Programming Language</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=0321562992" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
<li><a href="http://www.amazon.de/gp/product/3540278885?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3540278885">Auf der Fährte von C#</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3540278885" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
<li><a href="http://www.amazon.de/gp/product/0596007922?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=0596007922">Mono: A Developer&#8217;s Notebook</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=0596007922" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
<li><a href="http://www.amazon.de/gp/product/3772371051?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3772371051">Mono.NET goes LINUX</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3772371051" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/wie-installiere-ich-monodevelop/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Meine IP-Adresse mit Python herausfinden</title>
		<link>http://www.datenteiler.de/meine-ip-adresse-mit-python-herausfinden/</link>
		<comments>http://www.datenteiler.de/meine-ip-adresse-mit-python-herausfinden/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 17:12:56 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=250</guid>
		<description><![CDATA[Wie man seine IP-Adresse im Internet in der Shell und/oder mit Perl herausbekommt, habe ich ja bereits gezeigt. Was aber, wenn man diese Adresse auch in der Python-Shell braucht? Dafür habe ich die Funktion myIP geschrieben: import httplib &#160; def myIP&#40;&#41;: verb = httplib.HTTPConnection&#40;'www.whatismyip.com'&#41; verb.request&#40;'GET', '/automation/n09230945.asp'&#41; antw = verb.getresponse&#40;&#41; html = antw.read&#40;&#41; &#160; return html [...]]]></description>
			<content:encoded><![CDATA[<p>Wie man seine IP-Adresse im Internet in der Shell und/oder mit Perl herausbekommt, <a href="http://www.imhorst.net/get-your-ip-address-with-perl/" target="_blank">habe ich ja bereits gezeigt</a>. Was aber, wenn man diese Adresse auch in der Python-Shell braucht? Dafür habe ich die Funktion <code>myIP</code> geschrieben:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">httplib</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> myIP<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    verb = <span style="color: #dc143c;">httplib</span>.<span style="color: black;">HTTPConnection</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'www.whatismyip.com'</span><span style="color: black;">&#41;</span>
    verb.<span style="color: black;">request</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'GET'</span>, <span style="color: #483d8b;">'/automation/n09230945.asp'</span><span style="color: black;">&#41;</span>
    antw = verb.<span style="color: black;">getresponse</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    html = antw.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">return</span> html</pre></div></div>

<p>Zunächst wird das Modul <code>httplib</code> importiert. Dann wird mit <code>HTTPConnection</code> zu der Seite von <em>whatismyip.com</em> eine Verbindung hergestellt, der Quelltext der Unterseite <em>/automation/n09230945.asp</em> ausgelesen und in der Variablen <code>html</code> gespeichert. Der Quelltext besteht bereits einzig und allein aus der einzelnen IP-Adresse, so dass man hier nicht mit regulären Ausdrücken arbeiten muss, um sie auszuschneiden. Zum Schluss wird der Inhalt der Variablen <code>html</code> auf dem Python-Prompt ausgegeben. Wenn man die Funktion interaktiv in der Python IDLE testet, sieht das etwa so aus:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> myIP<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #483d8b;">'209.85.238.20'</span></pre></div></div>

<p>Wahrscheinlich gibt es das schon, vielleicht geht das auch noch einfacher, und ich hätte nur danach suchen müssen, aber selber programmieren macht einfach am meisten Spaß und man lernt immer etwas dabei.</p>
<p>Um Python zu lernen, ist übrigens <a href="http://www.amazon.de/gp/product/382732517X?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=382732517X">das Buch Python von Peter Walerowskis</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=382732517X" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> ein wirklich guter Einstieg. Auf verständliche Erklärungen folgen Codebeispiele und man bekommt nach und nach ein tieferes Verständnis für die Sprache. Einziger Nachteil ist, dass es sich um die erste Auflage handelt und sich der ein oder andere Fehler eingeschlichen hat. Im Text kann man darüber ja noch hinwegsehen, in den Beispielen sind sie aber ärgerlich. In <em>Listing 4.1</em> auf Seite 105 muss es z.B. <code>class Train(object):</code> heißen und nicht <code>class Train(objekt):</code>. Wenn man das Beispiel so abtippt, wie es da steht, bekommt man eine Fehlermeldung und ist als Anfänger eventuell damit überfordert, sie zu beheben. Aber auf der anderen Seite, wenn man den Fehler findet, kann es auch ein schönes Gefühl sein, als Schüler den Meister zu korrigieren.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/meine-ip-adresse-mit-python-herausfinden/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mobiles Python II</title>
		<link>http://www.datenteiler.de/mobiles-python-ii/</link>
		<comments>http://www.datenteiler.de/mobiles-python-ii/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 20:41:05 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Gnu/Linux]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Mobilfunk]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=176</guid>
		<description><![CDATA[Ich habe zwar immer noch keine Ahnung, ob ich es jemals gebrauchen werde, aber immerhin kann ich jetzt die Python-Konsole meines Nokia E65 (S60-Serie) über Bluetooth mit meinem Gnu/Linux-Rechner verbinden. Im August habe ich im ersten Teil Mobiles Python darüber geschrieben, wie man das mit dem Terminal von MacOS X schaffen kann. Nun kommt der [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe zwar immer noch keine Ahnung, ob ich es jemals gebrauchen werde, aber immerhin kann ich jetzt die Python-Konsole meines Nokia E65 (S60-Serie) über Bluetooth mit meinem Gnu/Linux-Rechner verbinden. Im August habe ich im ersten Teil <a href="http://www.imhorst.net/?p=156">Mobiles Python</a> darüber geschrieben, wie man das mit dem Terminal von MacOS X schaffen kann. Nun kommt der lang ersehnte zweite Teil, in dem ich zeige, wie das Ganze mit einem weiteren Unix-artigen Betriebssystem funktioniert. Zum Testen habe ich diesmal Ubuntu 7.10 &#8220;Gutsy Gibbon&#8221; genommen, das ich meiner Freundin Carola zuliebe auf unseren PC installiert habe, den wir gemeinsam nutzen. Mit anderen Linux-Distributionen dürfte das aber genauso funktionieren.</p>
<p>Zuerst braucht man folgende Programmpakete, falls sie noch nicht installiert sein sollten:</p>
<ul>
<li><strong>bluez-hcidump</strong></li>
<li><strong>cu</strong></li>
</ul>
<p>Bei einem Debian-ähnlichen Betriebssystem wie Ubuntu kann man einen Paketmanager wie <em>aptitude</em> verwenden, um die Pakete zu installieren.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> bluez-hcidump cu bluez-utils</pre></div></div>

<p>Nachdem erfolgreich installiert wurde, sollte man ersteinmal schaun, ob Bluetooth richtig installiert ist, indem man nach vorhandenen Geräten scannt:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> modprobe bluetooth hci_usb
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>bluetooth restart
hcitool scan
Scanning ...
        00:<span style="color: #000000;">17</span>:E4:<span style="color: #000000;">10</span>:<span style="color: #000000;">93</span>:3A       Christians-E65</pre></div></div>

<p>Super, das Handy wird schonmal erkannt. Dann muss man sich nur noch über die Bluetooth-Konsole einloggen. Voraussetzung dafür ist natürlich, dass Python auf dem Handy der S60-Serie installiert worden ist, wie im <a href="http://www.imhorst.net/?p=156">ersten Teil</a> beschrieben.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sdptool add <span style="color: #660033;">--channel</span>=<span style="color: #000000;">3</span> SP
rfcomm listen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0 <span style="color: #000000;">3</span></pre></div></div>

<p>Das Bluetooth-Protokoll RFCOMM emuliert an /dev/rfcomm0 eine serielle Schnittstelle, von der aus auf Kanal 3 gelauscht wird, ob ein weiteres Bluetooth-Gerät bereit ist. Jetzt muss im Python-Terminal des Telefons die <strong>Bluetooth console</strong> gestartet werden. Die Konsole sucht automatisch nach dem nächstbesten Gerät, mit dem es sich verbinden kann, und bietet dazu die lauschende Schnittstelle auf dem Gnu/Linux-PC an. Im Terminal erscheint jetzt</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rfcomm listen <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0 <span style="color: #000000;">3</span>
Waiting <span style="color: #000000; font-weight: bold;">for</span> connection on channel <span style="color: #000000;">3</span>
Connection from 00:<span style="color: #000000;">17</span>:E4:<span style="color: #000000;">10</span>:<span style="color: #000000;">93</span>:3A to <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0
Press CTRL-C <span style="color: #000000; font-weight: bold;">for</span> hangup</pre></div></div>

<p>und die Shell ist blockiert. Um die Verbindung mit <em>cu</em> zu startet öffnet man ein neues Terminal und kann loslegen:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cu <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0
Connected.
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span></pre></div></div>

<p>Die Python-Konsole auf meinem E65 wird nun von meinem Linux-Rechner quasi &#8220;ferngeteuert&#8221;. Über die Konsole kann ich Befehle an das Telefon schicken und schauen, was auf dem Handy-Display passiert:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> appuifw
appuifw.<span style="color: black;">note</span><span style="color: black;">&#40;</span>u<span style="color: #483d8b;">'Hallo Welt. ;-)'</span>, <span style="color: #483d8b;">'info'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Sollte die Verbindung nicht zustande kommen und stattdessen die Fehlermeldung</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cu: open <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0<span style="color: #7a0874; font-weight: bold;">&#41;</span>: Permission denied
cu: <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>rfcomm0: Line <span style="color: #000000; font-weight: bold;">in</span> use</pre></div></div>

<p>ständig erscheinen, versucht man vermutlich gerade, sich als Root oder mit <em>sudo</em> als Super-User mit dem Handy zu verbinden. Das klappt nicht. Man muss dazu (ausnahmsweise mal) normaler Nutzer sein.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/mobiles-python-ii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Die Welt in Gänsefüßchen</title>
		<link>http://www.datenteiler.de/der-welt-ein-gansefuschen/</link>
		<comments>http://www.datenteiler.de/der-welt-ein-gansefuschen/#comments</comments>
		<pubDate>Thu, 18 Oct 2007 18:02:15 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=174</guid>
		<description><![CDATA[Da hat man schonmal einen Roman geschrieben, will ihn dann in LaTeX setzen und bekommt entweder eine Fehlermeldung oder stellt fest, dass die Anführungszeichen alle oben gesetzt sind. Tatsächlich habe ich natürlich keinen Roman geschrieben, dafür aber einen kleinen Text, in dem die geraden Anführungszeichen (&#034;) am Anfang und Ende eines Satzes LaTeX-spezifisch mit geraden [...]]]></description>
			<content:encoded><![CDATA[<p>Da hat man schonmal einen Roman geschrieben, will ihn dann in LaTeX setzen und bekommt entweder eine Fehlermeldung oder stellt fest, dass die Anführungszeichen alle oben gesetzt sind. <br />
Tatsächlich habe ich natürlich keinen Roman geschrieben, dafür aber einen kleinen Text, in dem die geraden Anführungszeichen (&#034;) am Anfang und Ende eines Satzes LaTeX-spezifisch mit geraden Anführungszeichen und Akzent (&#034;&#096;) und am Ende des Satzes mit geraden Anführungszeichen und Apostroph (&#034;&#039;) gesetzt werden sollen, damit an deren Stelle später im PDF geschwungene Gänsefüßchen oben und unten zu sehen sind.<br />
Zuerst habe ich versucht, den Text mit dem Unix-Befehl <a href="http://de.wikipedia.org/wiki/Sed_(Unix)">sed</a> zu bearbeiten, konnte aber keine guten Ergebnisse erzielen. Also dachte ich an Perl, weil es sich am besten dazu eignet, mit regulären Ausdrücken, also mit bestimmten Suchmustern, einen Text zu durchsuchen und zu bearbeiten. In einem Kaufrausch hatte ich mir mal das <a href="http://www.amazon.de/gp/product/3897213664?ie=UTF8&#038;tag=imhorstnet-21&#038;linkCode=as2&#038;camp=1638&#038;creative=6742&#038;creativeASIN=3897213664">Perl Kochbuch</a><img src="http://www.assoc-amazon.de/e/ir?t=imhorstnet-21&#038;l=as2&#038;o=3&#038;a=3897213664" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> aus dem O&#8217;Reilly Verlag zuglegt. Zu meinem Glück gibt es am Ende des Kapitels über Mustererkennung einen Regex-Baukasten. Regex ist die Kurzform vom englischen &#8220;<strong>reg</strong>ular <strong>ex</strong>pression&#8221;, was zu Deutsch halt regulärer Ausdruck heißt. In diesem Regex-Baukasten gibt es Hilfe für mein Problem: <em>&#034;Gerade&#034; Anführungszeichen in &#8221;geschwungene, deutsche&#8220; Anführungszeichen (&#8221;Gänsefüßchen&#8220;) umwandeln.</em><br />
Damit konnte ich mir ein kleines Perl-Skript basteln, das dann die Aufgabe für mich erledigt hat:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
<span style="color: #666666; font-style: italic;"># gaensefuesschen.pl - Verwandelt gerade Anführungszeichen in </span>
<span style="color: #666666; font-style: italic;"># geschwungene Gänsefüßchen oben und unten in LaTeX.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>EIN<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt; $ARGV[0]&quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #b1b100;">or</span>
   <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Datei $ARGV[0] konnte nicht geoeffnet werden<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>AUS<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt; $ARGV[1]&quot;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #b1b100;">or</span>
   <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Datei $ARGV[1] konnte nicht geoeffnet werden<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #000066;">undef</span> <span style="color: #0000ff;">$/</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$text</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;EIN&gt;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> locale<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$text</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/&quot;([^&quot;]*)&quot;/\&quot;\`$1\&quot;\'/g</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> AUS <span style="color: #0000ff;">$text</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>EIN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>AUS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Das Skript <em>gaensefuesschen.pl</em> wird im Ordner mit dem Text abgespeichert und muss noch ausführbar gemacht werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x gaensefuesschen.pl</pre></div></div>

<p>Danach ist es einsatzbereit:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>gaensefuesschen.pl Text_alt.tex Text_neu.tex</pre></div></div>

<p>In der Datei <em>Text_neu.tex</em> kann man schließlich die Veränderungen bewundern.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/der-welt-ein-gansefuschen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mobiles Python</title>
		<link>http://www.datenteiler.de/mobiles-python/</link>
		<comments>http://www.datenteiler.de/mobiles-python/#comments</comments>
		<pubDate>Mon, 13 Aug 2007 19:03:56 +0000</pubDate>
		<dc:creator>Christian Imhorst</dc:creator>
				<category><![CDATA[MacOS X und iPhone]]></category>
		<category><![CDATA[Programmieren]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Mobilfunk]]></category>

		<guid isPermaLink="false">http://www.imhorst.net/?p=156</guid>
		<description><![CDATA[Ich habe zwar keine Ahnung, ob ich es jemals gebrauchen werde, aber ich habe jetzt Python auf meinem Nokia Handy. Wenn die normalen in Java programmierten Spiele zu langweilig geworden sind, hat man jetzt zumindest ein wunderschönes neues Adventure, das einem die Zeit vertreibt. Wer zufällig ein Handy der Serie 60 besitzt, kann nachziehen. Für [...]]]></description>
			<content:encoded><![CDATA[<p>Ich habe zwar keine Ahnung, ob ich es jemals gebrauchen werde, aber ich habe jetzt <a href="http://de.wikipedia.org/wiki/Python_(Programmiersprache)">Python</a> auf meinem Nokia Handy. Wenn die normalen in Java programmierten Spiele zu langweilig geworden sind, hat man jetzt zumindest ein wunderschönes neues Adventure, das einem die Zeit vertreibt. Wer zufällig ein Handy der Serie 60 besitzt, kann nachziehen. Für die Installation habe ich das <a href="http://www.mobilenin.com/pys60/menu.htm">englischsprachige Tutorial von Jürgen Scheible</a> benutzt. </p>
<p><span id="more-156"></span></p>
<p>Zuerst muss man herausfinden, welches S60 Handy man eigentlich genau besitzt. Ich habe zum Beispiel ein E65. Laut der Website <a href="http://forum.nokia.com/devices/matrix_s60_1.html">Device Specifications</a> sind die <a href="http://forum.nokia.com/devices/E65">Device Details</a> das Betriebssystem <em>Symbian OS v9.1</em> und die Plattform <em>S60 3rd Edition</em>. Die verschiedenen Versionen des Open Source-Programms PyS60, der Portierung von Python auf Symbian-Geräte, findet man bei <a href="http://sourceforge.net/project/showfiles.php?group_id=154155">SourceForge.net</a>. Die für mich wichtigen Dateien waren <em>PythonForS60_1_4_0_3rdEd.sis</em> und, damit man schon ein paar Skripte mit Beispielen hat, <em>PythonScriptShell_1_4_0_3rdEd.sis</em>. Die Endung <em>.sis</em> zeigt bei Symbian immer an, dass die Datei auf dem Gerät noch installiert werden muss.</p>
<p>Danach habe ich eine Verbindung zwischen Computer und Handy hergestellt. Das kann man entweder mit dem Datenkabel oder über Bluetooth machen. Da mein iBook eine Bluetooth-Schnittstelle hat, habe ich mich für letzteres entschieden. Bei beiden Geräten, iBook und E65, muss Bluetooth aktiviert sein. Das E65 stellt da keine großen Herausforderungen, MacOS 10.3 und 10.4 bringen entsprechende Programme mit. In Panther hat man noch das &#8220;Bluetooth Dienstprogramm&#8221; benutzt, in Tiger gibt es das nicht mehr, da benutzt man den Eintrag &#8220;Bluetooth&#8221; in den &#8220;Systemeinstellungen&#8221;, um beide Geräte miteinander bekannt zu machen. Mit dem Dienstprogramm &#8220;Bluetooth Datenaustausch&#8221; kann man dann beide Dateien an das Handy schicken, zum Beispiel in einen Ordner der SD-Speicherkarte. Wenn die Dateien abgespeichert sind, gibt es für Symbian einen Dateimanger, beim E65 unter dem Menüpunkt &#8220;Office&#8221;, mit dem man in den Ordner mit den beiden Installationsdateien surft und dort zuerst <em>PythonForS60_1_4_0_3rdEd.sis</em> und dann <em>PythonScriptShell_1_4_0_3rdEd.sis</em> installiert. Das Programm Python findet man danach im Installationsordner. </p>
<p>Klickt man den Programmbutton an, startet gleich die Python-Konsole. Allerdings kann man jetzt noch nichts eingeben, da man erstmal unter &#8220;Optionen&#8221; drei Auswahlmöglichkeiten hat:</p>
<ul>
<li><strong>Run script</strong>, um ein Skript aus dem Python-Ordner auszuführen.</li>
<li><strong>Interactive console</strong>, das ist die Konsole.</li>
<li><strong>Bluetooth console</strong>, damit kann man Python &#8220;fernsteuern&#8221;.</li>
</ul>
<p>Unter <strong>Run script</strong> findet man ein paar Beispiel-Skripte, die man gleich ausprobieren kann, und <strong>Interactive console</strong> ist eine typische Python-Konsole. Allerdings ist es ganz schön mühsam, Befehle mit dem Daumen einzutippen, so als würde man eine SMS schreiben. Daher ist die Bluetooth-Konsole eine geniale Erfindung, um über die Bluetooth-Schnittstelle eine Konsolen-Sitzung zu erzeugen (das HowTo habe ich von <a href="http://www.eriksmartt.com/blog/archives/55">eriksmartt.com</a>).<br />
Die Geräte sollten via Blutooth miteinander verbunden sein und im &#8220;Bluetooth Dienstprogramm&#8221;, bzw. im Reiter &#8220;Bluetooth&#8221; in den Systemeinstellungen ist beim Seriellen Anschluss &#8220;Bluetooth-PDA-Sync&#8221; die Schnittstelle &#8220;RS-232&#8243; eingestellt, anstatt Modem. Mit dem Befehl </p>
<pre>screen /dev/tty.Bluetooth-PDA-Sync</pre>
<p>im Terminal, kann man dann den Port auf das Terminal umleiten und danach im Handy die <strong>Bluetooth console</strong> starten. Nachdem man die Frage richtig beantwortet hat, welchen Port man auf dem System verwenden will, in diesem Beispiel ist es der Port &#8220;Bluetooth-PDA-Sync&#8221;, wird der Port gleich auf das Terminal umgeleitet.</p>
<p><a href='http://www.imhorst.net/wp-content/uploads/2007/08/pys60.png' title='pyS60'><img src='http://www.imhorst.net/wp-content/uploads/2007/08/pys60.png' alt='pyS60' /></a></p>
<p>Die Python-Konsole wird von meinem iBook nun quasi &#8220;ferngeteuert&#8221;. Ich kann über die Konsole Befehle an das Handy schicken und schauen, was passiert.</p>
<p>Die nächste Herausforderung wird sein, das ganze unter Linux zum Laufen zu bekommen. Dabei kann vielleicht das <a href="http://wiki.opensource.nokia.com/projects/Python_for_S60">Python for S60-Wiki</a> von Nokia helfen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.datenteiler.de/mobiles-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

