During work on client bindings for AT-SPI this week python managed to surprise me in a couple of ways.
- Lambda doesn’t work as I think it should.
lambda x: del(x)results in a syntax error. This is clearly stated in the python language reference:
lambda_form ::= "lambda" [parameter_list]: expressionThe
delstatement is not an expression; unsurprisingly its a statement. Its still pretty non-intuitive.
- You cant weak reference a weak reference.
This must be an implementation issue. I’m sure a weak reference of a weak reference makes sense. It did to me at the time!
__slots__is the most useful thing in the world.
Just take a look at this graph. Its the results of a totally scientific, completely well researched, test into the size of different structures in python. They are all holding roughly the same amount of information.
Structure Type Memory use (kB) Slot Object 18988 Tuple 19252 List 19476 Dict 42768 Object 44320