Deprecated: Assigning the return value of new by reference is deprecated in /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-includes/cache.php on line 36

Deprecated: Assigning the return value of new by reference is deprecated in /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-includes/query.php on line 21

Deprecated: Assigning the return value of new by reference is deprecated in /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-includes/theme.php on line 540

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-includes/cache.php:36) in /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-content/plugins/enhanced-wp-contactform/wp-contactform.php on line 264

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-includes/cache.php:36) in /customers/getonthenet.eu/getonthenet.eu/httpd.www/wp-content/plugins/enhanced-wp-contactform/wp-contactform.php on line 264
Getonthenet.eu » python

Posts Tagged ‘python’

Python annoyance

Thursday, January 29th, 2009

What really annoys me about python lists (and tuples) is that their ‘append’ method returns ‘None’.  This effectively renders the append method useless when working with custom classes that offer a dict like interface via __getitem__ and __setitem__.

Take the following code for example.

class MyClass( object ):

    def __init__( self ):
        self.dict = {}

    def __getitem__( self, name ):
        return self.dict[name]

    def __setitem__( self, name, value ):
        self.dict[name] = value

myclass = MyClass()
myclass["list"] = ["foo"]
myclass["list"].append( "bar" )

You’d think that myclass[”list”] now contains [”foo”, “bar”]. It actually contains None (the append methods return value).