perl: ${$i) , python: ?

Tim Hammerquist tim at vegeta.ath.cx
Wed Jan 2 15:06:47 EST 2002


Hans Nowak <wurmy at earthlink.net> graced us by uttering:
> Maxes wrote:
>> How to create variables with dynamic names ?
[ snip Perl code using symbolic references ]
> 
> It's questionable whether this is good coding practice, but
> the Pythonic equivalent would be something like
[ snip Python code using exec ]

This is pretty much the reason symbolic references are so vehemently
discouraged in the Perl community. symrefs date back to pre-ref perl
that didn't support hardrefs like Perl5 does.

exec in Python (like eval in both Python and Perl) are not to be
taken lightly either.

Both symrefs and the exec/eval pair are alleged to be valuable tools,
but there is nearly always a solution that 1) doesn't need them and 2)
are therefore much safer. I don't imagine the OP's case is any
different.

In any case, abuse (by programmer or end user) can lead to obscure bugs
and/or security issues.  They should all be used with caution.

Tim Hammerquist
-- 
The two surviving chocolate people copulate desperately, losing
themselves in a melting frenzy of lust, spending the last of their
brief, borrowed lives in a spasm of raspberry cream and fear.
    -- Narrator, The Sandman



More information about the Python-list mailing list