exec and locals
alister.ware at ntlworld.com
Thu Feb 27 10:59:11 CET 2014
On Thu, 27 Feb 2014 00:31:56 +0000, Steven D'Aprano wrote:
> On Wed, 26 Feb 2014 14:00:59 +0000, Alister wrote:
>> On Wed, 26 Feb 2014 13:15:25 +0000, Steven D'Aprano wrote:
>>> I have to dynamically generate some code inside a function using exec,
>>> but I'm not sure if it is working by accident or if I can rely on it.
>> I have no idea but as exec is generally considered to be a bad idea are
>> you absolutely sure this is the correct way to achieve your end goal?
>> perhaps if you detailed your requirement someone may be able to suggest
>> a safer solution.
> Thanks for your concern, but what I'm doing is perfectly safe. The
> string being exec'ed is a string literal known at compile-time and
> written by me (see my previous email for details) and the only reason
> I'm running it with exec at runtime rather than treating it as normal
> source code is that it relies on a feature that may not be available
> (with statement).
> The joys of writing code that has to run under multiple incompatible
> versions of Python.
I hadn't noticed who had made the original post or a I wouldn't have
bothered, you know Python & what is safe far better than I ever will
The world is not octal despite DEC.
More information about the Python-list