« June 2010 | Main | September 2010 »

July 31, 2010

antiheroes

One of many, many things to love about British comics is their uneasy relationship with the idea of the superhero. Alan Moore:

. I've come to the conclusion that what superheroes might be -- in their current incarnation, at least -- is a symbol of American reluctance to involve themselves in any kind of conflict without massive tactical superiority. I think this is the same whether you have the advantage of carpet bombing from altitude or if you come from the planet Krypton as a baby and have increased powers in Earth's lower gravity. That's not what superheroes meant to me when I was a kid. To me, they represented a wellspring of the imagination. Superman had a dog in a cape! He had a city in a bottle! It was wonderful stuff for a seven-year-old boy to think about. But I suspect that a lot of superheroes now are basically about the unfair fight. You know: people wouldn't bully me if I could turn into the Hulk.. I've come to the conclusion that what superheroes might be -- in their current incarnation, at least -- is a symbol of American reluctance to involve themselves in any kind of conflict without massive tactical superiority. I think this is the same whether you have the advantage of carpet bombing from altitude or if you come from the planet Krypton as a baby and have increased powers in Earth's lower gravity. That's not what superheroes meant to me when I was a kid. To me, they represented a wellspring of the imagination. Superman had a dog in a cape! He had a city in a bottle! It was wonderful stuff for a seven-year-old boy to think about. But I suspect that a lot of superheroes now are basically about the unfair fight. You know: people wouldn't bully me if I could turn into the Hulk.

This isn't new (is anything?). Distrust of superheroes, for example, formed a minor part of the postwar public hysteria over "horror comics". Here's a particularly OTT rant from a young Labour MP, in full-throated think of the children populism:

it is the glorification of violence, the educating of children in the detail of every conceivable crime, the playing on sadism, the morbid stimulation of sex, the cultivation of race hatred, the cultivation of contempt for work, the family and authority, and, probably most unhealthy, the cultivation of the idea of the superman and a sort of incipient Fascism.

The fact that Superman had been denounced as Jewish by Goebbels didn't seem to stop this, nor did the broader Jewish context to superhero comics.

Those denunciations aren't in themselves all that interesting; more compelling is the history of British comics toying with these ideas, deconstructing and critiquing the superhero rather than ignoring him. This has been one of the main occupations of British comics from the 80s onwards. Here's Grant Morrison talking it up as national source of pride:

Sick, ironic humour is very cool here. People are poor, drunk and vibrant with twisted creative energy. Taboo-smashing is an artistic pasttime that's become almost passe....It's no surprise we've produced so many spiky, brilliant, politically-motivated creators like Pat Mills, Garth Ennis, Jamie Delano or Warren Ellis. Alan Moore, Mark Millar and I are almost unique among our peers in our genuine fondness for American superhero characters. Otherwise, British writers pretty much HATE superheroes to a man, preferring ultraviolent soldiers, hi-tech vigilantes or kid gangs. In the saccharine world of 80s mainstream US titles it's probably easy to see in hindsight why the British Invasion of the 80s and 90s was so invigorating.

July 29, 2010

Roma

[Britain]:

Dale Farm is the largest Romany Gypsy and Irish Traveller site in the UK, and part of it is due for demolition. A number of Gypsies and Travellers have lived at Dale Farm entirely legally since the 1960s. Over the years, more families came to join them after councils began shutting down public sites and Travellers were forced to look for permanent places to settle.
France:
French President Nicolas Sarkozy on Wednesday (28 July) announced his government is to order police to round up allegedly illegal migrants of Roma ethnicity for expulsion from French territory and destroy their encampments. The announcement was the result of a cabinet meeting dedicated to the subject called after officers shot and killed a gypsy youth in the Loire Valley, provoking a riot by others of his community.

July 15, 2010

Nested dictionaries in python

Python's defaultdict is perfect for making nested dictionaries -- especially useful if you're doing any kind of work with json or nosql. It provides a dict which returns a default value when a key isn't found. Set that default value an empty dict, and you have a convenient dict of dicts:


>>> from collections import defaultdict
>>> foo = defaultdict(dict)
>>> foo['x']
{}

But it breaks down when you go more than one layer deep:


>>> foo['x']['y']
Traceback (most recent call last):
  File "", line 1, in 
KeyError: 'y'

You can get another layer by passing in a defaultdict of dicts as the default:


>>> bar = defaultdict(lambda: defaultdict(dict))
>>> bar['x']['y']
{}

But suppose you want deeply-nesting dictionaries. This means you can refer as deeply into the hierarchy as you want, without needing to check whether the intermediate dictionaries have already been created. You do need to be sure that intervening levels aren't anything other than a recursive defaultdict, mind. But if you know you're going to have your content filed away inside, say, quadruple-nested dicts, this isn't necessarily a problem.

One approach would be to extend the method above, with lambdas inside lambdas:


>>> baz = defaultdict(lambda: defaultdict(lambda:defaultdict(dict)))
>>> baz[1][2][3]
{}
>>> baz[1][2][3][4]
Traceback (most recent call last):
  File "", line 1, in 
KeyError: 4
>>> 

It's marginally more readable if we use partial rather than lambda:


>>> thud = defaultdict(partial(defaultdict, partial(defaultdict, dict)))
>>> thud[1][2][3]
{}

But still pretty ugly, and non-extending. Want infinite nesting instead? You can do it with a recursive function:


>>> def infinite_defaultdict():
...     return defaultdict(infinite_defaultdict)
... 
>>> spam = infinite_defaultdict() #defaultdict(infinite_defaultdict) is equivalent
>>> spam['x']['y']['z']['l']['m']
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {})

This works fine. The repr output is annoyingly convoluted, though:

>>> spam = infinite_defaultdict()
>>> spam['x']['y']['z']['l']['m']
defaultdict(, {})
>>> spam
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {'x': 
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {'y': 
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {'z': 
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {'l': 
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {'m': 
defaultdict(<function infinite_defaultdict at 0x7fe4fb0c9de8>, {})})})})})})

A cleaner way of achieving the same effect is to ignore defaultdict entirely, and make a direct subclass of dict. This is based on Peter Norvig's original implementation of defaultdict:


>>> class NestedDict(dict):
...     def __getitem__(self, key):
...         if key in self: return self.get(key)
...         return self.setdefault(key, NestedDict())


>>> eggs = NestedDict()
>>> eggs[1][2][3][4][5]
{}
>>> eggs
{1: {2: {3: {4: {5: {}}}}}}