py3k feature proposal: field auto-assignment in constructors

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Jan 28 12:19:06 EST 2008


Paddy a écrit :
(snip)

> Is it not possible to write a function that queries its call stack
> when run to find the name of all arguments and locals() of the level
> above

> so you could write:
> 
> class test(object):
>   def __init__(self, x, y):
>     arg2inst()
> 
> and automatically assign self.x=x; self.y=y ?

Might be possible using the inspect module. But as far as I'm concerned, 
I'm not sure I really like the idea that much - no rationale here, just 
a feeling...




More information about the Python-list mailing list