> On 23 Sep 2023, at 08:54, Stephen J. Turnbull > <turnbull.stephen...@u.tsukuba.ac.jp> wrote: > > Dom Grigonis writes: > >> Simply eval/exec string inputs. I sometimes use of these for ad-hoc >> callbacks. Would be great if `v` was recognised as a code. > > Looking at the example, do you mean '=' here? That is, you want to > add semantics for prefixed '=', meaning "just insert the expression > string here"? Correct, it’s the one that I though could make sense, so just keep using it in examples now.
>> Code is similar to this: class A: >> def __init__(self): >> self.d = {'a': 1, 'b': 2} >> >> def apply(self, smtp): >> for k, v in self.d.items(): >> if callable(smtp): >> self.d[k] = smtp(v) >> elif isinstance(smtp, str): >> self.d[k] = eval(f'{=v}{smtp}') > > Since f'{=v}' just results in 'v', why isn't > > self.d[k] = eval(f'v{smtp}') > > fine? Sure, you get the compiler check/refactoring benefit, but as > you admit, this is a very "ad hack" use case. I don't think we should > encourage it in production code. Agree, this use case is not for production code. Correct me if I am wrong, but I think `eval` in general should not be encouraged in production code. _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/N74S6AEKQEXG467DA5CWOW2DAO7KAWN6/ Code of Conduct: http://python.org/psf/codeofconduct/