RFC: Assignment as expression (pre-PEP)
Alex Martelli
aleax at mac.com
Sun Apr 8 11:56:13 EDT 2007
Dustan <DustanGroups at gmail.com> wrote:
> >>> class Wrapper(object):
> def __init__(self, obj):
> self.obj = obj
> def getit(self):
> return self.obj
> def setit(self, obj):
> self.obj = obj
> return obj
Yeah, that's substantialy the same approach I posted as a Python
Cookbook recipe almost six years ago, see
<http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66061> .
My specific use case for that recipe was when using Python to code a
"reference algorithm" found in a book, so that deep restructuring was
unwanted -- a similar but opposite case is using Python to explore
prototype algorithms that would later be recoded e.g. in C (here, too,
you don't really want to refactor the Python code to use dictionaries
"properly", so assign-and-test is handy).
Alex
More information about the Python-list
mailing list