all() is slow?

Devin Jeanpierre jeanpierreda at gmail.com
Thu Nov 10 15:37:05 EST 2011


> '--' not being allowed for a name has *nothing* to do with exec, and
> everything to do with `--` not being a valid Python identifier.

The only reason valid python identifiers come into it at all is
because they get pasted into a string where identifiers would go, and
that string is passed to exec().

So really, does it have "nothing" to do with exec? Or does your
argument eventually boil down to the use of exec?

> is more readable than

Of course not. I do, however, think that it's conceivable that I'd
want to key a namedtuple by an invalid identifier, and to do that,
yes, I'd need to use getattr().

Devin

On Thu, Nov 10, 2011 at 1:43 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Devin Jeanpierre wrote:
>>
>> Well. It reads fine in a certain sense, in that I can figure out
>> what's going on (although I have some troubles figuring out why the
>> heck certain things are in the code). The issue is that what's going
>> on is otherworldly: this is not a Python pattern, this is not a normal
>> approach. To me, that means it does not read fine.
>
> Certainly it's a Python pattern -- it's what you do to dynamically generate
> code.
>
>
>> The use of exec also results in (seemingly) arbitrary constraints on
>> the input. Like, why can't "--" be a name? Because exec? Is there some
>> other reason?
>
> '--' not being allowed for a name has *nothing* to do with exec, and
> everything to do with `--` not being a valid Python identifier.
>
>
>> '--' is a valid attribute name on virtually any object that supports
>> attribute setting (e.g. function objects). Of course, you need to use
>> setattr() and getattr(). Is this really the reason, or is it a
>> limitation caused primarily by the usage of exec and the need to
>> prevent code injection? If somebody added this feature later on, would
>> this create a security vulnerability in certain projects that used
>> namedtuple in certain ways?
>
> So you think
>
>    somevar = getattr(my_named_tuple, '--')
>
> is more readable than
>
>    somevar = my_named_tuple.spam
>
> ?
>
> ~Ethan~
> --
> http://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list