[Python-ideas] Quick idea: defining variables from functions that take the variable name
Steven D'Aprano
steve at pearwood.info
Wed Jun 1 14:30:51 EDT 2016
On Tue, May 31, 2016 at 11:13:30AM -0700, Brendan Barnwell wrote:
> ># okay
> >name -> sympy.Symbol()
>
> I don't like this that much, because it looks odd to have the
> expression on the right without the argument. The syntax doesn't make
> it at all clear how the T gets used on the RHS.
*shrug*
You have to learn it, just like you have to learn decorator syntax. It's
literally a *one sentence explanation*:
"The name on the left hand side is passed to the function on the right
hand side, as a string, as the first positional argument."
[...]
> > But this is allowed:
> >
> > my_name -> f(g()) # like f('my_name', g())
>
> So. . . what exactly will be allowed?
Guido suggested that we restrict it similar to the restrictions on
decorator syntax. I'd be okay with that. Without looking up the syntax,
from memory:
@decorate
@name.decorate
@factory() # no arguments, returns a decorator
@factory(args, keyword=foo)
and possibly a few others. So by analogy:
x -> Function()
x -> module.Function()
x -> module.Function(args, keyword=foo)
etc.
--
Steve
More information about the Python-ideas
mailing list