Thanks. That cdef-locals concept is consistent with the following example:
def f():
i = 1
def g(): print('i' in globals(), 'i' in locals())
def h(): print('i' in globals(), 'i' in locals()); i
g()
h()
f()
False False
False True
It is a mystery, which may be why the documentat
I did a few tests
# test 1
def f():
i = 1
print(locals())
exec('y = i; print(y); print(locals())')
print(locals())
a = eval('y')
print(locals())
u = a
print(u)
f()
{'i': 1}
1
{'i': 1, 'y': 1}
{'i': 1, 'y': 1}
{'i': 1, 'y': 1, 'a': 1}
1
# test 2
def f():
i = 1
On 7/20/22, george trojan wrote:
>
> 1. This works as I expect it to work:
>
> def f():
> i = 1
> print(locals())
> exec('y = i; print(y); print(locals())')
> print(locals())
> exec('y *= 2')
> print('ok:', eval('y'))
> f()
In CPython, the locals of a function scope (as op
Peter Otten於 2019年9月20日星期五 UTC+8下午3時31分48秒寫道:
> jf...@ms4.hinet.net wrote:
>
> x = 3
> def foo():
> > ... exec("print(globals(), locals()); x = x + 1; print(globals(),
> > locals())") ...
> foo()
> > {'foo': , '__package__': None, '__builtins__':
> > {, '__loader__': > {'_froze
jf...@ms4.hinet.net wrote:
x = 3
def foo():
> ... exec("print(globals(), locals()); x = x + 1; print(globals(),
> locals())") ...
foo()
> {'foo': , '__package__': None, '__builtins__':
> {, '__loader__': {'_frozen_importlib.BuiltinImporter'>, '__doc__': None, '__name__':
> {'__
>>> x = 3
>>> def foo():
... exec("print(globals(), locals()); x = x + 1; print(globals(),
locals())")
...
>>> foo()
{'foo': , '__package__': None, '__builtins__':
, '__loader__': , '__doc__': None, '__name__': '__main__',
'__spec__': None, 'x': 3} {}
{'foo': , '__package__': None, '__builti
Am Donnerstag, 19. September 2019 20:24:49 UTC+2 schrieb Peter Otten:
> Eko palypse wrote:
>
> > Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten:
> >> Eko palypse wrote:
> >>
> >> > No, I have to correct myself
> >> >
> >> > x = 5
> >> > def f1():
> >> > exec("x = x + 1;
Eko palypse wrote:
> Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten:
>> Eko palypse wrote:
>>
>> > No, I have to correct myself
>> >
>> > x = 5
>> > def f1():
>> > exec("x = x + 1; print('f1 in:', x)")
>> > return x
>> > print('f1 out', f1())
>> >
>> > results in t
Am Donnerstag, 19. September 2019 18:31:43 UTC+2 schrieb Peter Otten:
> Eko palypse wrote:
>
> > No, I have to correct myself
> >
> > x = 5
> > def f1():
> > exec("x = x + 1; print('f1 in:', x)")
> > return x
> > print('f1 out', f1())
> >
> > results in the same, for me confusing, result
First thank you for all the answers, very much appreciated.
I assume the root cause might be explained by the zen of python as well.
If the implementation is hard to explain, it's a bad idea.
Maybe I need to rethink my implementation :-)
Eren
--
https://mail.python.org/mailman/listinfo/python-l
Eko palypse wrote:
> No, I have to correct myself
>
> x = 5
> def f1():
> exec("x = x + 1; print('f1 in:', x)")
> return x
> print('f1 out', f1())
>
> results in the same, for me confusing, results.
>
> f1 in: 6
> f1 out 5
Inside a function exec assignments go to a *copy* of the local
No, I have to correct myself
x = 5
def f1():
exec("x = x + 1; print('f1 in:', x)")
return x
print('f1 out', f1())
results in the same, for me confusing, results.
f1 in: 6
f1 out 5
Eren
--
https://mail.python.org/mailman/listinfo/python-list
Eko palypse wrote:
> Thank you, I'm currently investigating importlib and read that
> __builtins__ might be another alternative.
> My ultimate goal would be to have objects available without the need to
> import them, regardless whether used in a script directly or used in an
> imported module.
I
Richard Damon wrote:
> On 9/19/19 6:16 AM, Eko palypse wrote:
>>> In all cases, if the optional parts are omitted, the code is executed in
>>> the current scope. ...
>>>
>>>
>>> You can see from it that "globals" is optional.
>>> And that, if "globals" is missing, then
>>> "exec" is executed in th
I’m not the OP, but I want to thank you for that clarification. I had
previously not understood the ramifications of the following in section “7.
Simple statements” in “The Python Language Reference”:
“An augmented assignment expression like x += 1 can be rewritten as x = x + 1
to achieve a si
On 9/19/19 6:52 AM, Eko palypse wrote:
> Am Donnerstag, 19. September 2019 12:45:35 UTC+2 schrieb Richard Damon:
>> On 9/19/19 6:16 AM, Eko palypse wrote:
In all cases, if the optional parts are omitted, the code is executed in
the current scope. ...
You can see from it th
Am Donnerstag, 19. September 2019 12:56:59 UTC+2 schrieb Peter Otten:
> Eko palypse wrote:
>
> >> Then it should be clear that the name 'test01' is put into globals(), if
> >> load_module() doesn't throw an exception. No sharing or nesting of
> >> namespaces takes place.
> >
> > Thank you too for
Eko palypse wrote:
>> Then it should be clear that the name 'test01' is put into globals(), if
>> load_module() doesn't throw an exception. No sharing or nesting of
>> namespaces takes place.
>
> Thank you too for your answer. Ok, that means that in every case when exec
> imports something it has
Am Donnerstag, 19. September 2019 12:45:35 UTC+2 schrieb Richard Damon:
> On 9/19/19 6:16 AM, Eko palypse wrote:
> >> In all cases, if the optional parts are omitted, the code is executed in
> >> the current scope. ...
> >>
> >>
> >> You can see from it that "globals" is optional.
> >> And that, i
On 9/19/19 6:16 AM, Eko palypse wrote:
>> In all cases, if the optional parts are omitted, the code is executed in the
>> current scope. ...
>>
>>
>> You can see from it that "globals" is optional.
>> And that, if "globals" is missing, then
>> "exec" is executed in the current scope ("f1" in your
> Then it should be clear that the name 'test01' is put into globals(), if
> load_module() doesn't throw an exception. No sharing or nesting of
> namespaces takes place.
Thank you too for your answer. Ok, that means that in every case when exec
imports something it has its own global namespace,
> In all cases, if the optional parts are omitted, the code is executed in the
> current scope. ...
>
>
> You can see from it that "globals" is optional.
> And that, if "globals" is missing, then
> "exec" is executed in the current scope ("f1" in your case).
Thank you for your answer, and that
Eko palypse wrote:
> exec('import test01', globals())
> print('f3 out', x)
>
> # result exception, expected but because f1 didn't throw an exception
> # I'm confused. module test01 has only this two lines
> x += 1
> print('f3 in:', x)
The lines above run in the test01's global namespace, not in
Eko palypse writes:
> Why does f1 work? I've expected an exception as no global dict has been
> provided
> ...
>def f1(...):
> exec("...")
>...
The documentation ("https://docs.python.org/3/library/functions.html#exec";)
tells you:
exec(object[, globals[, locals]])
...
In all cases, if the opt
On 1/22/18 3:22 AM, ken...@gameofy.com wrote:
I'm using exec() to run a (multi-line) string of python code. If an
exception occurs, I get a traceback containing a stack frame for the
string. I've labeled the code object with a "file name" so I can
identify it easily, and when I debug, I find
ken...@gameofy.com writes:
> I'm using exec() to run a (multi-line) string of python code. If an
> exception occurs, I get a traceback containing a stack frame for the
> string. I've labeled the code object with a "file name" so I can
> identify it easily, and when I debug, I find that I can inter
On 1/22/18 3:22 AM, ken...@gameofy.com wrote:
(BTW, I've written a simple secure eval())
You have accurately guessed our interest! Would you mind starting a new
thread to show us your simple secure eval?
--Ned.
--
https://mail.python.org/mailman/listinfo/python-list
On Mon, Jan 22, 2018 at 7:22 PM, wrote:
>
>
> I'm using exec() to run a (multi-line) string of python code. If an
> exception occurs, I get a traceback containing a stack frame for the string.
> I've labeled the code object with a "file name" so I can identify it easily,
> and when I debug, I fin
On Tue, Aug 2, 2016 at 1:45 AM, Lawrence D’Oliveiro
wrote:
> On Friday, July 29, 2016 at 6:25:51 AM UTC+12, Enjoys Math wrote:
>
>> exec('obj = ' + objType + '(self)', None, _locals)
>> obj = _locals['obj']
>
> Why? Why not just
>
> obj = objType(self)
I think
On Friday, July 29, 2016 at 6:25:51 AM UTC+12, Enjoys Math wrote:
> exec('obj = ' + objType + '(self)', None, _locals)
> obj = _locals['obj']
Why? Why not just
obj = objType(self)
?
--
https://mail.python.org/mailman/listinfo/python-list
On Thu, Jul 28, 2016 at 6:40 PM, Chris Angelico wrote:
> On Fri, Jul 29, 2016 at 1:47 AM, Enjoys Math wrote:
>> I've manually set breakpoints and traced this app crash back to this
>> function:
>>
>> def loadLSobjsOfType(self, objType, listJ):
>> if listJ != None:
>> for o
On Thu, Jul 28, 2016, at 11:47, Enjoys Math wrote:
> So what's the proper way to get the return value of an exec call when
> there is one?
Exec calls do not have return values.
If you need to pass an object out of the exec call to the surrounding
context, you can wrap it in an exception and throw
On Fri, Jul 29, 2016 at 1:47 AM, Enjoys Math wrote:
> I've manually set breakpoints and traced this app crash back to this
> function:
>
> def loadLSobjsOfType(self, objType, listJ):
> if listJ != None:
> for objJ in listJ:
> _locals = locals()
>
On Tue, Mar 22, 2016 at 11:57 PM, Steven D'Aprano wrote:
> Anyone have any idea what is going on here?
>
>
> def test():
> spam = 1
> exec("spam = 2; print('inside exec: %d' % spam)")
> print('outside exec: %d' % spam)
>
>
> In Python 2.7:
>
> py> test()
> inside exec: 2
> outside exec
On Wed, Mar 9, 2016 at 5:25 PM, Veek. M wrote:
> ah, okay - i'm familiar with the py3 syntax where you do:
> eval('whatever stmt', globals={}, locals={})
> I suppose this: exec " " in NS; syntax is strictly py2?
>
> Many thanks :)
Yeah, that's one of the things that was cleaned up in Py3. Several
Steven D'Aprano wrote:
> On Wednesday 09 March 2016 16:27, Veek. M wrote:
>
>> What is the return value of `exec`? Would that object be then used to
>> iterate the sequence in 'a'? I'm reading this:
>> https://www.python.org/download/releases/2.2.3/descrintro/
>
>
> exec is a statement, not a f
Ben Finney wrote:
> "Veek. M" writes:
>
>> What is the return value of `exec`?
>
> You can refer to the documentation for questions like that.
> https://docs.python.org/3/library/functions.html#exec>
>
>> Would that object be then used to iterate the sequence in 'a'?
>
> The ‘for’ or ‘while’
On Wednesday 09 March 2016 16:27, Veek. M wrote:
> What is the return value of `exec`? Would that object be then used to
> iterate the sequence in 'a'? I'm reading this:
> https://www.python.org/download/releases/2.2.3/descrintro/
exec is a statement, not a function, so it doesn't have a return
"Veek. M" writes:
> What is the return value of `exec`?
You can refer to the documentation for questions like that.
https://docs.python.org/3/library/functions.html#exec>
> Would that object be then used to iterate the sequence in 'a'?
The ‘for’ or ‘while’ statements are correct for iteration.
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
On 10/30/2012 08:57 AM, Helmut Jarausch wrote:
> On Tue, 30 Oct 2012 08:33:38 -0400, Dave Angel wrote:
>
>> On 10/30/2012 08:00 AM, Helmut Jarausch wrote:
>>> Hi,
>>>
>>> I'd like to give the user the ability to enter code which may only rebind
>>> a given set of names but not all ones.
>>> This do
On Tue, Oct 30, 2012 at 11:57 PM, Helmut Jarausch
wrote:
> Given spreadsheet S (Source) and D (Destination) as objects (wrapping a
> dictionary) a possible (legal) input would be
>
> D.price= D.price-S.discount
>
> No other fields of 'D' should be modifiable.
That's a bit harder. What you're des
On Tue, 30 Oct 2012 08:33:38 -0400, Dave Angel wrote:
> On 10/30/2012 08:00 AM, Helmut Jarausch wrote:
>> Hi,
>>
>> I'd like to give the user the ability to enter code which may only rebind
>> a given set of names but not all ones.
>> This does NOT work
>> A=1
>> B=2
>> Code=compile('A=7','','exec
On 10/30/2012 08:00 AM, Helmut Jarausch wrote:
> Hi,
>
> I'd like to give the user the ability to enter code which may only rebind
> a given set of names but not all ones.
> This does NOT work
> A=1
> B=2
> Code=compile('A=7','','exec')
> exec(Code,{'A':0})
> print("I've got A={}".format(A)) # prin
On Tue, Oct 30, 2012 at 11:00 PM, Helmut Jarausch
wrote:
> Hi,
>
> I'd like to give the user the ability to enter code which may only rebind
> a given set of names but not all ones.
>
> How can 'filter' the gobal namespace such that modifying 'A' is allowed
> but any attempt to modify 'B' should g
Prasad, Ramit wrote:
> Hi Peter,
>
> >>> class Magnitude(object):
>
> ... def __init__(self, value):
> ... self.value = value
> ... def __call__(self, uf=1):
> ... if uf == 1:
> ... return self
> ... return self.value
> ...
>
> >>>
Thank you, that really made things much easier and admittedly much less nasty
too.
Regards
Rolf
On 01/03/12 18:14, Peter Otten wrote:
> Rolf Wester wrote:
>
>> The reason to use exec is just laziness. I have quite a lot of classes
>> representing material data and every class has a number of pa
Rolf Wester wrote:
> The reason to use exec is just laziness. I have quite a lot of classes
> representing material data and every class has a number of parameters.
> The parameter are Magnitude objects (they have a value and a unit and
> overloaded special functions to correctly handle the units)
Rolf Wester wrote:
The reason to use exec is just laziness.
The worst reason for using it. So I hope you carefully read Steven's comment
and get rid of exec() for anything serious:
<4f4f85eb$0$29989$c3e8da3$54964...@news.astraweb.com>
Ciao, Michael.
--
http://mail.python.org/mailman/listinf
Hi,
thanks for your replies so far.
The reason to use exec is just laziness. I have quite a lot of classes
representing material data and every class has a number of parameters.
The parameter are Magnitude objects (they have a value and a unit and overloaded
special functions to correctly handle
On Thu, 01 Mar 2012 14:07:15 +0100, Rolf Wester wrote:
> Hi,
>
> I would like to define methods using exec like this:
>
> class A:
> def __init__(self):
> cmd = "def sqr(self, x):\nreturn x**2\nself.sqr = sqr\n"
> exec cmd
> a = A()
> print a.sqr(a, 2)
That's... nasty,
On 1 March 2012 13:07, Rolf Wester wrote:
> Hi,
>
> I would like to define methods using exec like this:
>
> class A:
> def __init__(self):
> cmd = "def sqr(self, x):\n return x**2\nself.sqr = sqr\n"
> exec cmd
> a = A()
> print a.sqr(a, 2)
>
> This works, but I have to call sq
Rolf Wester wrote:
Hi,
I would like to define methods using exec like this:
class A:
def __init__(self):
cmd = "def sqr(self, x):\nreturn x**2\nself.sqr = sqr\n"
exec cmd
a = A()
print a.sqr(a, 2)
This works, but I have to call sqr with a.sqr(a, 2), a.sqr(2) does not wo
Michele Petrazzo wrote:
> Hi all,
> I'm playing with python internals and I'm discovering a strange behavior
> of isinstance. Considering the following test case:
>
> test/bar.py
> test/b.py
> test/a/__init__.py
> test/a/foo.py
>
> -- __init__.py -> empty
>
> --- foo.py:
> class foo: pass
> c =
On Mar 26, 3:10 pm, Irmen de Jong wrote:
> On 26-3-2010 22:58, wukong wrote:
>
> > newbie question, how do you run a .exe generated by MSVC++ in python
> > in windows?
>
> Use the subprocess module, for instance:
> subprocess.call(["notepad.exe", "d:/file.txt"])
>
> irmen
worked like a charm, :-)
On 26-3-2010 22:58, wukong wrote:
newbie question, how do you run a .exe generated by MSVC++ in python
in windows?
Use the subprocess module, for instance:
subprocess.call(["notepad.exe", "d:/file.txt"])
irmen
--
http://mail.python.org/mailman/listinfo/python-list
Gerald Britton wrote:
> On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy wrote:
>> On 2/3/2010 3:30 AM, Simon zack wrote:
>>>
>>> hi,
>>> I'm not sure how I can use exec within a function correctly
>>> here is the code i'm using:
>>>
>>> def a():
>>> exec('b=1')
>>> print(b)
>>>
>>> a()
>>>
>>> this w
I get no error:
>>> def a():
... exec('b=1')
... print(b)
...
>>> a()
1
>>>
On Wed, Feb 3, 2010 at 2:59 PM, Terry Reedy wrote:
> On 2/3/2010 3:30 AM, Simon zack wrote:
>>
>> hi,
>> I'm not sure how I can use exec within a function correctly
>> here is the code i'm using:
>>
>> def a():
>>
On 2/3/2010 3:30 AM, Simon zack wrote:
hi,
I'm not sure how I can use exec within a function correctly
here is the code i'm using:
def a():
exec('b=1')
print(b)
a()
this will raise an error, but I would like to see it outputting 1
Always **copy and paste** **complete error tracebac
On Mon, Nov 30, 2009 at 1:12 PM, Dave Angel wrote:
> Victor Subervi wrote:
>
>> On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote:
>>
>>
>>
>>> exec is a statement, and statements don't have "return values." It's
>>> not
>>> a function, so there are no parentheses in its syntax, either. exec
On Mon, Nov 30, 2009 at 12:25 PM, Carsten Haese wrote:
> Victor Subervi wrote:
> > Taking out the parenthesis did it! Thanks. Now, you state this is an
> > option of last resort. Although this does indeed achieve my desired aim,
> > here is a complete example of what I am trying to achieve. The fo
Victor Subervi wrote:
On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote:
exec is a statement, and statements don't have "return values." It's not
a function, so there are no parentheses in its syntax, either. exec is also
a technique of last resort; there's nearly always a better/safer
Victor Subervi wrote:
> Taking out the parenthesis did it! Thanks. Now, you state this is an
> option of last resort. Although this does indeed achieve my desired aim,
> here is a complete example of what I am trying to achieve. The following
> is from 'createTables2.py':
>
> for table in tables
Jean-Michel Pichavant wrote:
if which == '':
i = 0
all = ''
while i < len(meanings):
table = '%s\n' % meanings[i]
table += "\n \n
composing HTML like that is painful, bug prone and insecure
You should have a look at http://tottinge.blogsome.com/meaningfulnames/
I
Victor Subervi wrote:
if which == '':
i = 0
all = ''
while i < len(meanings):
table = '%s\n' % meanings[i]
table += "\n \n align='center'>%s\n " % names[i]
j = 0
for elt in code:
if (j + 8) % 8 == 0:
table += ' \n'
table += ' %s\
On Sun, Nov 29, 2009 at 10:23 PM, Dave Angel wrote:
> exec is a statement, and statements don't have "return values." It's not
> a function, so there are no parentheses in its syntax, either. exec is also
> a technique of last resort; there's nearly always a better/safer/faster way
> to accom
Dave Angel wrote:
exec is a statement, and statements don't have "return values." It's
not a function,
In 3.x, it is a function, though the use of print as a statement
indicates that the OP was using 2.x.
--
http://mail.python.org/mailman/listinfo/python-list
Victor Subervi wrote:
Hi;
I have the following line of code:
exec('%s()' % table)
where 'table' is a variable in a for loop that calls variables from another
script. I've made it so that it only calls one variable. I know for a fact
that it's calling that variable in the script because it found
Hans Larsen wrote:
Help!
I'm begginer in Python 3.+!
If i wih to update a module after an import and chages,
How could I do:
By "from imp import reload" and then reload(mymodule)
or how to use "exec(?)", it is mentoined in docs.
In Python ver. <3 reload(module) writes some
On 2 Nov, 10:49, "Hans Larsen" wrote:
> Help!
> I'm begginer in Python 3.+!
> If i wih to update a module after an import and chages,
> How could I do:
> By "from imp import reload" and then reload(mymodule)
> or how to use "exec(?)", it is mentoined in docs.
> In Python ve
Chris Rebert wrote:
On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin wrote:
Hi,
Being fairly new to Python, I'm trying to figure out the best way to use the
exec statement and I must admit that I am a bit lost.
Generally, if you want to use the exec statement, you're probably lost.
Unless yo
2009/9/2 Chris Rebert
> On Wed, Sep 2, 2009 at 1:13 PM, Quentin Lampin
> wrote:
> > 2009/9/2 Chris Rebert
> >>
> >> On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin >
> >> wrote:
> >> > Hi,
> >> > Being fairly new to Python, I'm trying to figure out the best way to
> use
> >> > the
> >> > exec sta
On Wed, Sep 2, 2009 at 1:13 PM, Quentin Lampin wrote:
> 2009/9/2 Chris Rebert
>>
>> On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin
>> wrote:
>> > Hi,
>> > Being fairly new to Python, I'm trying to figure out the best way to use
>> > the
>> > exec statement and I must admit that I am a bit lost.
>>
2009/9/2 Chris Rebert
> On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin
> wrote:
> > Hi,
> > Being fairly new to Python, I'm trying to figure out the best way to use
> the
> > exec statement and I must admit that I am a bit lost.
> >
> > Consider this case:
> > exec "print 'a'" in {},{} [exp.1]
On Wed, Sep 2, 2009 at 4:54 AM, Quentin Lampin wrote:
> Hi,
> Being fairly new to Python, I'm trying to figure out the best way to use the
> exec statement and I must admit that I am a bit lost.
>
> Consider this case:
> exec "print 'a'" in {},{} [exp.1]
> It means that I'm (kindly) asking the i
Thank you both for the explanation.
As a matter of fact RTFM doesn't -always- help. Sometimes I'm just
thick and I can read the manual 10 times and still not understand, as
it happened on this particular matter. Your contribution focused my
attention on the right bit of the manual which I somehow
Emanuele D'Arrigo schrieb:
Greetings everybody,
I don't quite understand why if I do this:
d = {}
exec("dir()", d)
1) d is no longer empty
2) the content of d now looks like __builtins__.__dict__ but isn't
quite it d == __builtins__.__dict__ returns false.
Can anybody shed some light?
RTF
Emanuele D'Arrigo wrote:
> Greetings everybody,
>
> I don't quite understand why if I do this:
>
d = {}
exec("dir()", d)
>
> 1) d is no longer empty
> 2) the content of d now looks like __builtins__.__dict__ but isn't
> quite it d == __builtins__.__dict__ returns false.
>
> Can anybo
"Gabriel Genellina" writes:
> En Mon, 25 May 2009 11:07:13 -0300, Jaime Fernandez del Rio
> escribió:
>> And since I'm asking, could something similar, i.e. defining a new
>> function and get a handle to it, be achieved with eval?
>
> No, because def is a statement, and eval only accepts an expr
En Mon, 25 May 2009 11:07:13 -0300, Jaime Fernandez del Rio
escribió:
These weekend I've been tearing down to pieces Michele Simionato's
decorator module, that builds signature preserving decorators. At the
heart of it all there is a dynamically generated function, which works
something similar
On Thu, 29 Jan 2009 08:15:57 -, Hendrik van Rooyen
wrote:
"Rhodri James" wrote:
To:
Sent: Thursday, January 29, 2009 6:12 AM
Subject: Re: Exec woes
On Wed, 28 Jan 2009 07:47:00 -, Hendrik van Rooyen
wrote:
> This is actually not correct - it is the root cause
"Rhodri James" wrote:
To:
Sent: Thursday, January 29, 2009 6:12 AM
Subject: Re: Exec woes
> On Wed, 28 Jan 2009 07:47:00 -, Hendrik van Rooyen
> wrote:
> > This is actually not correct - it is the root cause of my trouble.
> > if you write, in a nested scope
On Wed, 28 Jan 2009 07:47:00 -, Hendrik van Rooyen
wrote:
Stephen Hansen wrote:
Exec is a statement, not a function nor an object: even though you can
enclose parens around its arguments like you do later on, they
don't have any syntax meaning
This is actually not correct - it is th
Stephen Hansen wrote:
>Hendrik van Rooyen wrote:
>>IDLE 1.1.3 No Subprocess
> help(exec)
>>SyntaxError: invalid syntax
>
>>Its the same under Linux SuSe, Python 2.5.1.
>>
>>I think this is a BUG.
>
>Exec is a statement, not a function nor an object: even though you can enc
On Tue, Jan 27, 2009 at 9:34 AM, Christian Heimes wrote:
> Hendrik van Rooyen schrieb:
>> It starts with the conspiracy of silence at the interactive prompt:
>>
>> Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
>> win32
>> Type "copyright", "credits" or "license()" for m
1 - 100 of 170 matches
Mail list logo