whoami

My hackergotchi
Hey!
I'm Christopher. I am a software and technology enthusiast. Besides fiddling with bits and pieces I enjoy having a social life and doing sports. If you want to know more, there is a more elaborated About me page.

We all know that one of the cool things that Python offers is it’s interactive shell that makes it possible to quickly test things. It’s included in every Python release and can be invoked by simply entering ‘python’ on the command-line. While this is great already, the official interactive shell lacks several features that would be convenient (such as code completion, syntax hilighting, pasteservice support…). IPython is an attempt to provide an interactive python shell with the same capabilities, but additional goodies. I was using it mainly because it featured code completion.

I came to the python support channel today to ask about some strange behavior I had observed. Consider the following snippet:

    In [1]: class Foo(object):
    ...:     def __getattr__(self, attr):
    ...:         print attr
    ...:         
    ...:         

    In [2]: foo = Foo()

    In [3]: foo.asd
    asd
    asd

    In [4]: Foo().asd
    asd

Now this should of course print ‘asd’ once in every case. This is IPython’s fault and seems to be related to this bug report. When asking about this, somebody suggested bpython. I headed over to their page and was quite pleased by what I saw in their video. bpython features syntax hilighting, code completion, expected parameters, rewind and pastebin support. See for yourself:

video
9 comments Jun 2, 2009 4:19:00 PM bpython, coding, planet-ubuntu, python

Update: The below no longer applies. A fix has been released. (So you can undo any ugly hack you used in order to make it work.)

Dear Python developers,

when upgrading to Ubuntu 9.04 (Jaunty Jackalope, which is to be released in 22 days from now) please keep in mind that python-virtualenv (the tool we all know and love) is broken. It still works with python2.5, though.

While trying to resolve this issue I had several ideas:

  • Deinstall python2.6 so python2.5 is used instead. This turned out to be a bad idea.
  • Some may be used to update-alternatives. This can’t be used for python.
  • If you just change the symlink /usr/bin/python from /usr/bin/python2.6 to /usr/bin/python2.5 it will first seem to work, but some tasks will fail. E.g. when installing python2.5-dev, you will get the following error: ValueError: /usr/bin/python does not match the python default version. It must be reset to point to python2.6
  • You then need to do another ugly workaround.

I am not sure whether this will wreak further havoc, so please be cautious. I hope that we can get this fixed until Jaunty is released. There is a bug report.

Just letting you know. Took me some time to realize.

6 comments Apr 1, 2009 1:45:00 PM planet-ubuntu

This is just a short maintenance info. A few minutes ago I finished upgrading my blog (which is proudly powered by Zine) to the most recent available version (hg calls it tip). Since I was running quite an outdated version (some pre 0.1 alpha version) I had to convert a few things manually. From now on there will be proper support for upgrading all my Zine instances in one go painlessly. If you notice any remaining glitches that need to be ironed out, please add a comment to this posting.

I fixed some problem in Zine that was causing the Atom feed not to validate properly. I want to apologize in advance for any postings that might appear in your feedreader again. This won’t happen anymore but was inevitable.

(I usually don’t like maintenance postings on planets, but I want to check whether my feed still works. I will remove this posting from the planet after it has properly shown up.)

Happy new year!

2 comments Jan 2, 2009 10:19:00 PM maintenance, zine

Just a few minutes ago the python blogging engine Zine, codename “Aldus”, was released.

Initially called TextPress, the project has come a long way already. Despite being a 0.1 release, it is quite powerful already. It is incredibly easy to write plugins for it. This is due to both, the clever design of the code and the choice of programming language (python). It is even easier to customize it’s look with a theme. You basically just need to change a CSS file.

I have been using the development versions for over a year already for several blogs and I am happy to see the first stable release. This blog is itself powered by Zine and I am looking forward to upgrading to the new version.

For further reference, see the official project page at:
zine.pocoo.org

Merry Christmas to all of you!

1 comment Dec 24, 2008 5:15:00 PM Python, zine

One of my favorite games, Savage 2, is now available with no cost involved.

It has quite a unique gameplay and cannot be classified as belonging to a specific genre. The game is made up like this: There’s two teams fighting each other: humans and beasts. Each team has a headquarter the other team aims to destroy. (No surprises so far.) Each team has one commander and a bunch of “normal” players. The commander views the game from bird’s eye perspective like in Warcraft 3. The units he sees are partially under his control. The other units of his team are played by actual players. The players play in either first or third person mode.

It is a very strategic game and often one genius idea has a heavy influence on the outcome of the match. There’s quite a few more aspects I like about the game, but I don’t want to make this posting too long.

Just head over to the downloads section and get it for your architecture (Available for Windows, Linux 32 & 64 bit, OSX).

Screenshot Screenshot

(I usually don’t do advertising for commercial products, but this one is an exception since it’s one of the better games for linux.)

9 comments Dec 22, 2008 2:36:00 PM games

I have seen quite a few logos that look very similar or almost identical to the ubuntu logo. Let’s make a contest out of this and see who finds the most similar graphic.

This is the logo we all know:

Original Ubuntu Logo

The well-known logo of the Microsoft Alumni Network:

Logo of Microsoft Alumni Network

My current favorite (just discovered): The logo of Pool Invest:

Logo of Pool Invest

These are my candidates. Can you find others? (Logos of ubuntu derivates do not count!)

(Please note: The logos linked in this blogpost are trademarks of their respective owners. I am neither responsible for, nor affiliated with any of them. I am just linking them so you can have a good laugh. I am also not responsible for any of the content the linked websites contain. I am not implying that somebody copied or stole someone else’s property.)

13 comments Dec 15, 2008 2:48:00 PM no tags

Motivation

In this posting I want to explain a fundamental concept shared by many popular programming languages such as Python et al. Understanding this concept is key to working with objects, names and variables successfully. Those who don’t understand it often face difficulties at some point, and many questions asked on support channels reveal that not everybody knows about this. After reading this posting you will (hopefully) have understood why things behave the way they behave, so let’s dive in.

The Problem (one of them)

Consider the following code (if you want the code beautifully colored for easier reading, please visit my blog directly rather than reading through a planet):

    >>> class Foo(object):
    ...     def __init__(self):
    ...         self.my_attribute = "some string literal"
    ... 
    >>> foo = Foo()
    >>> bar = foo

This first defines a class Foo and an attribute self.my_attribute. (You can tell that this is an instance attribute because the definition takes place in the __init__ method. We will cover that in a later blog posting.) We then assign the string literal “some string literal” to the attribute. Now, every instance of class Foo is initialized with an attribute my_attribute with the value “some string literal”. After the definition of the class, we create an instance of it (By calling something Java folks would refer to as the constructor. Take note of the parentheses.) which we call foo. The next line is what is most interesting: One might say “bar equals foo”, but that is not as precise an idiom it should be. Let’s go on and see what happens.

    >>> foo.my_attribute
    'some string literal'
    >>> bar.my_attribute
    'some string literal'

This is easy. We just get the value stored in my_attribute. No surprises here. The next step, however, may be confusing to some.

    >>> bar.my_attribute = "it's a trap!"
    >>> foo.my_attribute
    "it's a trap!"

We assigned another string literal “it’s a trap!” to bar.my_attribute and for some reason (which I will explain shortly) foo.my_attribute changed to the very same string as well!

The Home of the Objects

When you instantiate an object from a class, there is no doubt that you need memory for your object (even if you didn’t specify any attributes on that class/object) to be stored. Upon creation of an object, that object is stored somewhere. (How this happens exactly is dependant on the languages implementation and is of no interest for us.) Consider this example:

    >>> Foo()
    <__main__.Foo object at 0xb7e791ac>

If you read the above carefully you will have noticed that this, again, creates an object of class Foo (indicated by the parentheses). The instance of Foo we just created lives somewhere (albeit, in CPython, only for a limited time as we shall soon see). Now, if we wanted to alter that objects my_attribute, how would we do it? The answer is: We can’t (I am simplifying here). “Why can’t we?” I hear you say. The explanation is, that we did not bind the object to a name. Binding an object to a name usually means selecting a unique identifier (like the very unique word “foo”), creating an instance of a class as we did above, and putting the = operator between those. Like this:

    >>> foo2 = Foo()

We now have bound (a new!) instance of class Foo to the name (or reference) foo2 (Check your languages specification to see what is allowed as a valid identifier). We can now do:

    >>> foo2
    <__main__.Foo object at 0xb7825e0c>

As you can see, foo2′s differs from the object we created above (the one that we didn’t bind to a name), because it actually is a new, different object. (The hexadecimal value 0xb7825e0c tells us where this object is stored but does not matter much. You will see other values for your machine.)

Let me visualize this (without the objects we created when we began):

The Home of the Objects

As you can see, the object we created last is bound to the name foo2. The other object is not bound to any name and thus not reachable for us.

You can now understand what happened when we initially did this:

    >>> class Foo(object):
    ...     def __init__(self):
    ...         self.my_attribute = "some string literal"
    ... 
    >>> foo = Foo()
    >>> bar = foo

On the very last line, we did not create an instance of class Foo, but instead just created another reference for that object. The very same object is now reachable with either name, foo and bar. Hence, if we change foo’s attributes we will alter bar’s as well and vice versa.

If you want to check whether two names are referring to the same object, you can use the is operator in Python like this:

    >>> foo is bar
    True
    >>> bar is foo
    True

Here you are checking for identity of both objects. Don’t confuse the is operator with the == operator (in Python), which checks for equality but not identity! (This is different for other languages like Java!)

Doing

    foo = 5

binds object 5 to foo, represented by the integer literal 5 (Yes, even ints are objects in Python). For performance reasons Python does not create a new object for every integer you use, but rather uses the same object for the same integer. With this, you have lost the (potentially last) reference to the object (to which the name foo was bound to just a minute ago).

If you want to delete your reference, you can just do:

    del foo

This does not necessarily delete your object! It only deletes the name. If, how and when the object itself is deleted is completely dependant on the implementation of Python you use. (This is said to be an implementation detail.)

Accessing a name after it has been deleted results in the following traceback:

    >>> foo
    Traceback (most recent call last):
      File "< stdin >", line 1, in < module >
    NameError: name 'foo' is not defined

Objects do not know what names they are bound to, if any. They actually don’t even have a name. The names we defined are just references to the objects.

You can reach objects not only by name. Consider the following example:

    >>> a = [Foo(), Foo(), Foo()]

Here we create a list (an object itself, by the way), create three instances of Foo and put them into the list. Note that we did not bind any of the objects to a name, except for the list, which is bound to “a”. The three instances are reachable via that name. They are said to be contained by the list and thus still reachable.

    >>> a
    [<__main__.Foo object at 0xb7cf9f4c>, <__main__.Foo object at 0xb7cf9e2c>, <__main__.Foo object at 0xb7cf9eec>]
    >>> a[0]
    <__main__.Foo object at 0xb7cf9f4c>
    >>> a[1]
    <__main__.Foo object at 0xb7cf9e2c>
    >>> a[2]
    <__main__.Foo object at 0xb7cf9eec>

Names have only limited visibility. The underlying concept is called the namespace. (I won’t go into more detail here. Just that you got something to search for.)

Conclusion

By now you should have understood the basic principle of object creation and name binding in languages like Python. If there are any questions remaining, feel free to drop a comment to this posting. If someone comes up to you and says “Take a look at my shiny Python variable!”, always keep in mind that it is actually a name, bound to an object.

Further reading:

2 comments Nov 22, 2008 1:17:00 PM Coding, Python

Do you know those moments in life when you discover some piece of software you didn’t know before and immediately fall in love with it, not knowing how you could survive without it for so long?
Well that just happened to me with Vimperator. Vimperator is a Firefox addon that (by default) takes away your menubar and other things of the standard Firefox interface and adds vim behaviour to your browser.

If you do not like vi/vim/gvim for whatever reason, skip this posting.

Once you installed the addon and restarted your browser you can go to the Vimperator introductional page by pressing F1. You will notice there is a tutorial in the Help topics section. If you are already familiar with basic vim usage you should be able to go over that tutorial in about 15 minutes. After you mastered the basics you will be able to efficiently surf the web with your Firefox browser without issueing the mouse (too often). (I have not encountered a situation where I really needed the mouse yet, but I imagine some flash applications will be hard to master without. I have no flash at hand at the moment, though. Note: You are still able to use your mouse even when Vimperator is active.)

If you tried some console based browsers in the past you may have gotten annoyed when trying to click some link at some spot within a page. Hitting TAB until you reach that specific link is no fun. Therefore Vimperator introduces a system called Hints. By pressing either the f or F key (open in this tab / open in new tab) you will notice that Vimperator adds a small red box with a number in it for each link on the page. You can now simply enter the number of the link you wish to open. Now that’s a much better concept than hitting TAB repeatedly.
Have you ever got annoyed by some textfield that was way too small for the text you were typing in it? Sure, you could just fire up your favorite editor and copy and paste your text after you are done. Vimperator has a nice shortcut for that. Once your focus is on some textfield, press CTRL+i. Vimperator then fires up gvim (make sure it is installed) and you can type your text in that editor window. After saving and closing the document, the text is automatically put into the texfield (this posting is written that way).

If you have any questions the excellent (so far) documentation fails to answer, /join #vimperator on irc.freenode.net.

So, if you like vim and want to make your browser more accessible for you without a mouse (or less accessible for anybody else who even has a mouse but does not know vim) you should definitely take a look at this very cool plugin.

Keep in mind that I’ve only used it for about two hours at the time of writing. If you know any other tricks, drop a comment.

Screenshot

5 comments Sep 20, 2008 6:49:00 PM firefox, nerdstuff, technology, vim

If you just want a bunch of interesting links, jump to Status Quo. You may be interested in my other thoughts too, though.

The Cornerstones

The first computer I ever sat in front of was an old Amstrad PC with monochrome display. I first accessed the internet with a 56k dial up modem (which happened years after getting in touch with computers) and as far as I remember, it was astonishing.

As you may have noticed computers evolved slightly since then. Today you get quad core processors, tiny flash memory sticks that can store more information than the hard disk drives most of us started with and of course much faster internet access. The technological progress that has been made significantly impacts the way we are interacting with modern pieces of technology, e.g. computers. We can now film ourselves or do screen recordings and put them somewhere on the internet so others can easily access them.

In fact nowadays there’s so much information out there that you need some really big search engine to dig through the masses of bits and bytes to find what you are searching for. The same applies for videos. Services like YouTube make it trivial to put videos up, watch them and make them accessible to the world.

The Value of Knowledge

It is a fact that knowledge and proper education leads to wealth (not speaking of money or expensive cars). Our goal therefore must be that everybody who wants it, gets the chance to learn. We must not deny proper education to some people just because they got no money. In such cases we should rather aim to support them. You can send food and clothes to people in need, sure. You don’t want them to starve. But at the same time you need to make sure that access to knowledge is provided as well, in order to allow those people to become independent of you.

The Prerequisites

The obvious question is: How do you best provide access to information and knowledge long-term?
My answer is: Teach people the prerequisites so they can take care of their education on their own.

The major problem was that you just cannot cheaply get a whole library up somewhere, filled with recent books of high quality. With todays technological advances however, you can! Just provide fast enough internet access and teach how to use it.

Sounds easy, doesn’t it? “People who cannot afford food and clothes cannot afford computers and internet access either!“ I hear you say. That is true. That’s why organizations such as Linux4Afrika were founded. That’s another reason for Ubuntus existence. There’s a bunch of things involved, but we are on the right track. (Another obvious thing is the need to understand the language most of the information is available in. So go and learn English if you havn’t already. It’s just so important.)

Status Quo

Assuming you fulfil the necessary requirements you already have access to quite a few good resources on the net.
(Disclaimer: The following list is by no means complete. If you know a good service for this list, please drop a comment!)

  • Wikipedia – I guess I don’t need to explain.
  • Google Tech Talks is a brilliant channel on YouTube containing hundreds (913, at the time of writing) of videos on technological topics.
  • The Stanford University launched a service called Stanford Engineering Everywhere, containing filmed lectures with good quality. (E.g. “Introduction to Computer Science“, “Artificial Intelligence“, “Linear Systems and Optimization“)
  • ShowMeDo is a service providing tutorial videos on popular technological topics.

I personally love learning things I think are interesting. When I was told that Stanford University now also make some of their lectures available online I felt the urgent need to write a posting about it and thought it was a good opportunity to outline the importance of such services and the availability of broadband internet access.
(Thanks Canonical for inspiring me with respect to the title of this post.)

2 comments Sep 18, 2008 3:45:00 PM better world, technology

After last years successful Ubuntu Conference (Ubucon in short) for the German-speaking community, the second German Ubuntu Conference will take place on 17., 18. and 19. of October 2008 in Göttingen, Germany (we were in Krefeld last year). The list of talks, workshops and discussions is available already.

If you have any questions you can find us in #ubucon-de on Freenode IRC.

See you there!

0 comments Sep 9, 2008 4:25:00 PM community, ubucon