def obj()

Leif K-Brooks eurleif at ecritters.biz
Thu Feb 8 16:59:02 EST 2007


Gert Cuykens wrote:
> def obj():
>    return {'data':'hello',
>                'add':add(v)}
> 
> def add(v):
>    data=data+v
> 
> if  __name__ == '__main__':
>    test=obj()
>    test.add('world')
>    print test.data
> 
> I don't know why but i have one of does none class c programing style
> moods again. I was wondering if the following was possible without
> using a class ?

def obj():
     result = {'data': 'hello'}
     result['add'] = adder(result)
     return result

def adder(obj):
     def add(value):
         obj['data'] += value
     return add

if __name__ == '__main__':
     test = obj()
     test['add']('world')
     print test['data']



More information about the Python-list mailing list