[Python-ideas] Way to repeat other than "for _ in range(x)"

Nick Coghlan ncoghlan at gmail.com
Fri Mar 31 00:13:26 EDT 2017


On 31 March 2017 at 04:08, Pavol Lisy <pavol.lisy at gmail.com> wrote:
> On 3/30/17, Nick Coghlan <ncoghlan at gmail.com> wrote:
>> On 31 March 2017 at 00:23, Pavol Lisy <pavol.lisy at gmail.com> wrote:
>>> Just for curiosity - if PEP-501 will be accepted then how many times
>>> could be fnc called in next code?
>>>
>>>     eval(i'{fnc()}, ' *3)
>>
>> Once (the same as f-strings), but then it would throw TypeError, as
>> unlike strings and other sequences, InterpolationTemplate wouldn't
>> define a multiplication operator.
>>
>> Cheers,
>> Nick.
>
> Could you explain the reason behind not implement it, please?

For the same reason dictionaries don't implement it: it doesn't make
any sense in the general case.

Repeating the *rendered* template might make sense, but that will
depend on the specific renderer and the kinds of objects it produces
(e.g. an SQL or shell renderer probably wouldn't produce output that
supported repetition).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list