How to write Smart Python programs?

Bruno Desthuilliers onurb at xiludom.gro
Wed Oct 11 07:16:31 EDT 2006


Theerasak Photha wrote:
> On 10/11/06, Bruno Desthuilliers <onurb at xiludom.gro> wrote:
> 
>> 2/ functions that returns a status code and modify their arguments.
> 
> Argument modification for lists with one item is *sometimes* used to
> emulate full lexical closure. (or at least that's what the folks on
> freenode #python told me)

Yes, but that's another point. What I was talking about (perhaps not
clearly) is mutable arguments used as returned values, ie:

C-smell:

def my_func(res):
  bar =  foo()
  if bar is None:
    return 1 # error
  else:
    res['bar'] = bar
    res['baaz'] = "blah"
    return 0 # no error

pythonic:

def my_func():
  bar = foo()
  if bar is None:
    raise FooBarError("no bar from foo")
  return dict(bar=bar, baaz='blah')


-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list