On Fri, 28 Feb 2014 00:29:35 +1300, Gregory Ewing wrote:
> Steven D'Aprano wrote:
>> On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote:
>>
>>>Why not just use this version all the time? It should work in both 2.x
>>>and 3.x.
>>
>> Because that's yucky. It's an aesthetic thing: when support
On Thu, Feb 27, 2014 at 10:29 PM, Gregory Ewing
wrote:
> Steven D'Aprano wrote:
>>
>> On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote:
>>
>>> Why not just use this version all the time? It should work in both 2.x
>>> and 3.x.
>>
>>
>> Because that's yucky. It's an aesthetic thing: when sup
Steven D'Aprano wrote:
On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote:
Why not just use this version all the time? It should work in both 2.x
and 3.x.
Because that's yucky. It's an aesthetic thing: when supported, I want the
Python interpreter to manage the context manager.
More y
On Thu, 27 Feb 2014 00:31:56 +, Steven D'Aprano wrote:
> On Wed, 26 Feb 2014 14:00:59 +, Alister wrote:
>
>> On Wed, 26 Feb 2014 13:15:25 +, 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 a
On Thu, Feb 27, 2014 at 3:47 PM, Steven D'Aprano wrote:
> Guys, I know that exec is kinda dangerous and newbies should be
> discouraged from throwing every string they see at it, but this isn't my
> second day Python programming, and it's not an accident that Python
> supports the dynamic compilat
On Wed, 26 Feb 2014 23:20:10 -0500, Dave Angel wrote:
> Before I would use exec, I'd look hard at either generating a
> source file to import,
Yes, I went through the process of pulling out the code into a separate
module, but that just made more complexity and was pretty nasty. If the
func
On Thu, 27 Feb 2014 16:34:33 +1300, Gregory Ewing wrote:
> Steven D'Aprano wrote:
>> except SyntaxError:
>> def inner():
>> # manually operate the context manager call context manager
>> __enter__
>> try:
>> try:
>>
Steven D'Aprano Wrote in message:
> On Wed, 26 Feb 2014 14:46:39 +0100, Peter Otten wrote:
>
>> 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 eventually set
On Thu, 27 Feb 2014 00:25:45 +, Steven D'Aprano wrote:
> By the way, if anyone cares what my actual use-case is, I have a
> function that needs to work under Python 2.4 through 3.4, and it uses
> a with statement. With statements are not available in 2.4 (or 2.5,
> unless you give a from __fut
Steven D'Aprano wrote:
except SyntaxError:
def inner():
# manually operate the context manager
call context manager __enter__
try:
try:
return something
except: # Yes, a bare except. Catch EVERYTH
On Wed, 26 Feb 2014 14:00:59 +, Alister wrote:
> On Wed, 26 Feb 2014 13:15:25 +, 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
On Wed, 26 Feb 2014 14:46:39 +0100, Peter Otten wrote:
> 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.
>>
>> Here is a trivial example:
>>
>>
>> py> def spam():
>> ...
On Wed, 26 Feb 2014 13:15:25 +, 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.
>
> Here is a trivial example:
>
>
> py> def spam():
> ... exec( """x = 23""" )
> ...
Peter Otten wrote:
> 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.
>>
>> Here is a trivial example:
>>
>>
>> py> def spam():
>> ... exec( """x = 23""" )
>> ...
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.
>
> Here is a trivial example:
>
>
> py> def spam():
> ... exec( """x = 23""" )
> ... return x
> ...
> py> spam()
> 23
On Thu, Feb 27, 2014 at 12:15 AM, Steven D'Aprano
wrote:
> py> def spam():
> ... exec( """x = 23""" )
> ... return x
> ...
> py> spam()
> 23
>
>
> (My real example is more complex than this.)
>
> According to the documentation of exec, I don't think this should
> actually work, and yet it
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.
Here is a trivial example:
py> def spam():
... exec( """x = 23""" )
... return x
...
py> spam()
23
(My real example is more complex than this.)
En Fri, 11 Jul 2008 03:51:39 -0300, Uwe Schmitt
<[EMAIL PROTECTED]> escribi�:
On 1 Jul., 15:15, Mel <[EMAIL PROTECTED]> wrote:
rocksportrockerwrote:
> the following code does not work until I ommit the "a=0" statement.
> def test():
> exec "a=3" in locals()
> print a
>
Uwe Schmitt wrote:
>> Apparently, exec in locals() knows nothing about slots (because locals()
>> is the only dictionary in the universe where slots would be involved ? --
>> perhaps not, but close).
>>
>> Mel.
>
> Thanks for your answer. I wonder if this is a bug, or did I miss
> something in th
On 1 Jul., 15:15, Mel <[EMAIL PROTECTED]> wrote:
> rocksportrockerwrote:
>
> > Hi,
>
> > the following code does not work until I ommit the "a=0" statement.
>
> > def test():
> > exec "a=3" in locals()
> > print a
> > a=0
>
> > test()
>
> > print raises:
> > Unbound
rocksportrocker wrote:
>
> Hi,
>
> the following code does not work until I ommit the "a=0" statement.
>
>
>def test():
>exec "a=3" in locals()
>print a
>a=0
>
> test()
>
> print raises:
> UnboundLocalError: local variable 'a' referenced before
> assignme
Hi,
the following code does not work until I ommit the "a=0" statement.
def test():
exec "a=3" in locals()
print a
a=0
test()
print raises:
UnboundLocalError: local variable 'a' referenced before
assignment
Can anybody explain what is going wrong here ?
Gree
22 matches
Mail list logo