[Python-ideas] Quick idea: defining variables from functions that take the variable name

Barry Scott barry at barrys-emacs.org
Thu Jun 9 05:01:15 EDT 2016


Problem is to remove the duplication of 'name' in expressions like this:

	name = cls( 'name', arg, kw=val )

Would using a builtin that gives the name of the variable being assigned to be 
enough? A builtin like lhs_variable_name() - not a great name.

	name = cls( lhs_variable_name(), arg, kw=val )

This escapes from the problem of knowing the name space that
name is in and needing to understand the details of the expression.

It does not need a decorator with the complexity of needing a
break down of the RHS expression.

Now I do not need the 'name' to be the first argument:

	name = function( arg, kw=lhs_variable_name() )

I'm not sure what the behavior  should be for multiple LHS names.

	name1, name2 = cls( lhs_variable_name(), arg )

Is this an error and an exception is raised?
Always return the first name, 'name1'?
Does lhs_variable_name() return a tuple of ('name1','name2')?
Does lhs_variable_name() take an argument to choose?

Barry



More information about the Python-ideas mailing list