Syntactic sugar for assignment statements: one value to multiple targets?

OKB (not okblacke) brenNOSPAMbarn at NObrenSPAMbarn.net
Wed Aug 17 15:13:36 EDT 2011


gc wrote:

> Maybe this is more visibly convenient with a complex class, like
> 
> x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...)
> 
> where you need three separate objects but don't want to duplicate the
> class call (for obvious copy-paste reasons) and where bundling it in a
> list comprehension:
> 
> x, y, z = [SuperComplexClass(param1, etc, ...) for _ in range(3)]
> 
> layers gunk on top of something that's already complex.

    	That just seems like an odd use case to me.  I rarely find myself 
wanting to make exactly N copies of the same thing and assign them to 
explicit names.  If I'm not making just one, it's usually because 
I'm making some sort of list or dict of them that will be accessed by 
index (not with names like "x", "y", and "z"), in which case a list 
comprehension is the right way to go.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown



More information about the Python-list mailing list