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

Barry Scott barry at barrys-emacs.org
Tue May 31 12:20:36 EDT 2016

> On 31 May 2016, at 02:16, Guido van Rossum <guido at python.org> wrote:
> In mypy we have a need for type variables, which are created like this:
>  from typing import TypeVar
>  T = TypeVar('T')
> I just saw a lightning talk about sympy where they define symbols to
> be used in mathematical equations, like this:
>  from sympy import Symbol
>  x = Symbol('x')
> I'm sure this is not a new idea, but so far I've always thought that
> this is pretty esoteric and the approach here is good enough. But
> maybe we can actually do better, and whatever solution we come up with
> might also be useful for extracting attributes from an object or
> values from a mapping?

Looks like the C #define is what is being asked for.

#define SYM( name ) name = Symbol( #name )

SYM( x )

Does python need macro preprocessor?


More information about the Python-ideas mailing list