Stoppt die Vorratsdatenspeicherung! Jetzt klicken & handeln!Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:

Python Reinteract

April 7, 2009 on 10:22 am | In python | 1 Comment

Wer schon mal mit einem Lisp oder Scheme System programmiert hat wird in heutigen “modernen” IDE’s das einfache Ausführen von Codeblocks vermissen. Zum Beispiel ist es in EMACS möglich einen Code Block mit CTRL-X -CTRL-E auszuführen.


emacs lisp-mode

Um ein ähnliches Konzept das etwa an die Shell von Mathematica erinnert, bemühte sich Owens Taylor von Red Hat mit seinem Reinteract. Reinteract steht seit dem 26. März in der Version 0.5.0 zu Verfügung. Versionen für Linux, Windows und OS X stehen zum download bereit.

Owen kam auf eine geniale Idee. Schaut euch mal folgenden kleinen Screenshot an.


reinteract

Nach der Eingabe von “a=[1,2]” und “print(a)” hab ich einfach CTRL-RETURN gedrückt. Sofort erscheint die die Lösung des kleinen 2 Zeilers unter der “print(a)” Zeile. Ändern wir nun die obere Zeile in “a=[1,2,3]” und drücken wieder CTRL-RETURN steht unter der “print(a)” Zeile sofort “[1,2,3]“. Dass solch eine Programmierhilfe für Pythonanfänger extrem hilfreich ist, muss man nicht diskutieren . Aber Reinteract kann natürlich noch viel mehr und dient auch den geübten Python Entwickler im Experimentieren. Zum Beispiel hab ich Letztens etwas mehr mit dem Namespace itertools von Python gespielt.


reinteract

Reinteract kann zusätzlich noch CodeCompletion und zeigt die __docs__ Hilfe an, wenn die Maus über einen Type oder einer Methode verweilt. In Verbindung mit numpy kann Reinteract sogar die Plot Ausgaben in dem Worksheet anzeigen.

Reinteract ist ein schöner Schritt für Python und man kann erwarten, das dieses Tool bald ein kleines Standardwerkzeug für Pythonentwickler wird.

Links:

  • Talk from Owen Taylor about Reinteract at PyCon 2009 Link
  • Home from Reinteract Link

PyRoom das WriterRoom für Linux

December 9, 2008 on 8:06 pm | In linux, python | 1 Comment

Mit PyRoom hat nun auch endlich ein Editor ala WriterRoom es auf den Linux Desktop geschafft. PyRoom wird wie der Name schon vermuten lässt in Python entwickelt. Die aktuelle Version 0.3.2 ist bei weitem noch nicht das Ende der Entwicklung von PyRoom. Als erstes fällt der etwas zu kleine Font auf. Auch wird etwas wenig Platz vom Bildschirm verwendet. Warum zum Beispiel nicht die Textfläche über die gesamte Höhe des Bildschirm geht ist schon etwas blöd. Aber kurz nachdem ich mich darüber geärgert habe, habe ich schon den Konfigurationsdialog ( CTRL-P ) gefunden und gleich die Textfläche und den Font vergrößert. Das geht fantastisch einfach und man sieht hinter dem Konfigurationsdialog gleich die neue Einstellung. Einfach super nun kann ich mich richtig über PyRoom freuen. Absolut hervorragend finde ich die Möglichkeit über CTRL-PAGEUP und CTRL-PAGEDOWN durch verschiedene Textbuffer zu wandern. Alles was nun noch fehlt ist der Tastaturton wie in Q10. Aber der wird sicherlich noch kommen.

Zum installieren ( Ubuntu 8.10 ) einfach die folgenden beiden Zeilen am Ende in die Datei die /etc/apt/sources.list einfügen.

deb http://ppa.launchpad.net/pyroom-dev/ubuntu intrepid main
deb-src http://ppa.launchpad.net/pyroom-dev/ubuntu intrepid main

Danach mit

sudo apt-get update && sudo apt-get install pyroom

Pyromm installieren. Schon findet man Pyroom im Anwendungsmenü unter dem Büro Menüpunkt. Mit CTRL-H die Hilfe aufrufen und schnell die paar Darstellungsoptionen anpassen und los gehts.

Dieser Text wurde natürlich auch mit Pyroom geschrieben. :-)

Screenshot und noch ein Bericht von anderen WriterRoom Clonen.

Hashtable vs. List

January 25, 2008 on 6:47 pm | In english, hacking, python | No Comments

Like every student of computer science, I had a course with the title „algorithm and data structures“. That is one of the classic subjects in informatics. You are learn things like linked list, tree’s and so on. Also different algorithm for searching. Sequential search, binary search and top-down 2-3-4 trees. It is a nice and important subject. Today we have frameworks like Java,.NET,Python and they all have build in data structures like lists and hashtables. With these technics it is quite easy to use a list. Here is a small and nice example in Python:

list = []
for i in range(10000):
   rand = random.randint(0,50000)
   if not rand in list:
      list.append(rand)

Now we have a list with up to 10000 random and unique entries. Very easy to program, but you also see the performance problem. In line 4 is a check for the uniqueness of the possible new entry. To check for existence of an element in a list, the framework runs through all elements of the list. That is a sequential search, the slowest searching algorithm in this universe. This small example needs 365360 microseconds on my machine.

Now lets try a different version with a dictionary.

dict = {}
for i in range(10000):
   rand = random.randint(0,50000)
   if not dict.has_key(rand):
      dict[rand] = 0

This example needs only 34908 microseconds. That is 10 times faster than the version with the list. It looks very stupid to program a line like “dict[rand] = 0�, but this solution now uses a different search algorithm. If you increment the loop up to 20000 entries the different is 83times. But in the near of 30000 it comes to a point where the insort algorithm of the dict structure needs so long that the speed benefit is over.

I wrote another small program to visualize the effect.
See the code

Hash Against List

I found this problem in a small textminig project. Using dictionarys to search for existence of a word in an document was extremely faster than a list. So sometimes you should think about, when to use a list and when use a dictionary like an list.

Workaround for pkg-config - ecplise CDT Problem

September 22, 2007 on 9:17 pm | In english, linux, open source, python, technic | 1 Comment

In the last days I started to learn a bit more GTK and GDK development. I like eclipse very much, but the new CDT version 4.0 have still no real feature to use the pkg-config tool from the freedesktop organisation. Thats makes me a bit nervous. In the first two small projects I copied all the include and lib pathes from the pkg-config output.

Example output:

-I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12 -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lfontconfig -lXext -lXrender -lXinerama -lXi -lXrandr -lXcursor -lXfixes -lpango-1.0 -lcairo -lX11 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

You know, that is not really funny. Some evenings ago I developed a small python script to solve this problem a bit.

The biggest problem is that eclipse creates the important XML node after configuring a extra directory or/and library. After you add for example a directory called “aaa” and an library called “aaa” you can close eclipse and run the python script.

pkg2eclpise.py -p <path to projectpath> -c <pkg-config params>

e.g.:

pkg2eclipse.py -p FirstGTKWindow/ -c “gtk-2.0 –cflags –libs”

After running the script, restart eclipse and you see all the directorys and librarys in your manipulated project. You can rerun the script again and again. The script avoid duplicated entrys

Have fun with the great CDT 4.0 and the nice fast code completion feature.

pkg2eclipse.py

Powered by WordPress with Pool theme design by Borja Fernandez.
Entries and comments feeds. Valid XHTML and CSS. ^Top^