A quick Python note

Have a look at this brief snippet:

In [2]: a = range(10)
In [3]: 3 in a
Out[3]: 1
In [4]: 3 not in a
Out[4]: 0
In [5]: not (3 in a)
Out[5]: 0

Input/output 4 should strike you as a tad strange if you don’t know Python that well but are familiar with similar constructs in other languages. At first glance, it almost seems like the sense of an operator can be negated with the not operator.

Read More

Python new-style objects and __slots__

This should be very useful:

In [5]: class oldObject:
   ...: ....def __init__(self):
   ...: ........self.someVar = 1
   ...:
In [6]: o1 = oldObject()
In [7]: o1.someVar = 2
In [8]: o1.someOtherVar = 3

This is of course expected behaviour. Have a look at this though:

In [9]: class newObject(object):
   ...: ....__slots__ = ['someVar']
   ...: ....def __init__(self):
   ...: ........self.someVar = 1
   ...:
In [10]: o2 = newObject()
In [11]: o2.someVar = 2
In [12]: o2.someOtherVar = 3
AttributeError: 'newObject' object has no attribute 'someOtherVar'

Neat huh? In short, deriving from the new Python class object means you have a “new-style” object. Amongs other things, this means that you can define a __slots__ list which will prevent the use of attributes not in that list. These objects are available from Python 2.2 onwards.

Read More

Where are the frikking WMDs?

Yes, where are those Weapons of Mass Destruction that the US was warning everybody about? Those same WMDs that were used as some of the primary excuses for violating Iraq have not popped up yet, it seems. Funny…

In related news, this article reports that there was a certain pressure by the US administration on the intelligence services to generate reports that would help to convince the public that attacking Iraq was urgent business. Also funny, right?

Read More

The American Propaganda Machine

Most of us outside the borders of the USA know this, but nothing we do or say will probably have any kind of effect on the status quo: The American government is supported by an extremely efficient propaganda machine that ensures that the majority of its citizens will support it in its most barbaric of ventures. The big problem is that this propaganda machine consists primarily, contrarily to tradition, of “independent” media entities.

Read More

Where should that dang button go?

So, here we have the Aqua Human Interface Guidelines (i.e. the MacOS-X user interface guidelines), the GNOME Human Interface Guidelines, the KDE User Interface Guidelines and of course the Microsoft Windows Official Guidelines for User Interface Developers and Designers (I came back in January of 2018 to fix this link — also interesting is the section on margins and spacing).

Apple says that “The default button for dismissing a dialog should go in the lower-right corner. If there’s a Cancel button, it should be to the left of the default button.”. Gnome seems to imply that the default button should be on the bottom right, with other buttons to its left, which is more or less consistent with the Apple guidelines.

Read More