Why return None?

Martin DeMello martindemello at yahoo.com
Wed Aug 25 10:26:26 CEST 2004


It seems to be a fairly common pattern for an object-modifying method to
return None - however, this is often quite inconvenient.

For instance

def f(lst1, lst2):
  g((lst1 + lst2).reverse()) # doesn't work!

you need to say

def f(lst1, lst2):
  a = lst1 + lst2
  a.reverse()
  g(a)

this is actually getting in my way a lot when scripting Blender - for
instance, I can't say move(Vector([a,b,c]).normalize()), I have to do
	a = Vector([a,b,c])
	a.normalize()
	move(a)

but it seems to be recommended practice rather than a fault in the
Blender API, since the standard list does it. Is there any drawback to
returning self rather than None?

martin

c

  





More information about the Python-list mailing list