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:
UnboundLocalError: local variable
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 the docs ???
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
a=0
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 ?
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
assignment
Can anybody
On Mar 14, 2008, at 4:41 AM, [EMAIL PROTECTED] wrote:
On Mar 14, 9:47 am, Justus Schwabedal [EMAIL PROTECTED]
wrote:
[snipped]
However when I do this:
bash-3.2$ cat execBug2.py
#! /usr/bin/python
header=
from scipy import randn
def f():
return randn()
def g():
exec
I'm trying to parallise with python. Specifically I'm sending code to
the processes and let them exec this code (in ascii form). However I
ran into a problem with Namespaces (I think) which I do not understand.
Here's what I do first:
---
bash-3.2$ cat
On Mar 14, 9:47 am, Justus Schwabedal [EMAIL PROTECTED]
wrote:
[snipped]
However when I do this:
bash-3.2$ cat execBug2.py
#! /usr/bin/python
header=
from scipy import randn
def f():
return randn()
def g():
exec header
return f()
print g() =,g()
bash-3.2$
Dear python users!
I try to setted up compile-free parallelism using the exec command.
However I had some problems with namespaces which I find mysterious
although I managed to work around. But the workaround is not nice, so
I wonder if there are ways.
I do the following,
bash-3.2$ cat
En Sun, 22 Jul 2007 10:36:59 -0300, [EMAIL PROTECTED]
escribió:
Since the application is transforming
its input, it could transform braces into indentation. Of course
*Python*
doesn't use braces, but the question was how to write pseudo-Python
without using indentation to indicate
On 23 srp, 09:19, Gabriel Genellina [EMAIL PROTECTED] wrote:
En Sun, 22 Jul 2007 10:36:59 -0300, [EMAIL PROTECTED]
escribió:
Since the application is transforming
its input, it could transform braces into indentation. Of course
*Python*
doesn't use braces, but the question was how to
On 21 srp, 22:31, Steve Holden [EMAIL PROTECTED] wrote:
...:::JA:::... wrote:
Hello,
After my program read and translate this code:
koristi os,sys;
ispisi 'bok kaj ima';
into the:
import os,sys;
print 'bok kaj ima';
and when it run this code with exec, I always get error like
On Sun, 22 Jul 2007 03:23:30 -0700, vedrandekovic wrote:
Thanks for everything previously, but just to I ask about code
indentation,this with { and } doesn't
employed, here is my example how can I solve this about code
indentation:
n=90
if n==90:
{print bok kjai ma'}
File
Steven D'Aprano wrote:
On Sun, 22 Jul 2007 03:23:30 -0700, vedrandekovic wrote:
Thanks for everything previously, but just to I ask about code
indentation,this with { and } doesn't
employed, here is my example how can I solve this about code
indentation:
n=90
if n==90:
{print
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with I'm afraid I don't understand this question. The OP is
writing a program to translate a Python-like language that uses
non-English keywords into Python. Since the application is transforming
its input, it could
On Sun, 22 Jul 2007 09:12:21 -0400, Steve Holden wrote:
Steve Holden was playing silly games. You can't use { } for indentation.
You have to use indentation.
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with I'm afraid I don't understand this question. The
Steven D'Aprano wrote:
On Sun, 22 Jul 2007 09:12:21 -0400, Steve Holden wrote:
Steve Holden was playing silly games. You can't use { } for indentation.
You have to use indentation.
I wasn't playing silly games at all, and I did prefix that part ofmy
answer with I'm afraid I don't
Hello,
After my program read and translate this code:
koristi os,sys;
ispisi 'bok kaj ima';
into the:
import os,sys;
print 'bok kaj ima';
and when it run this code with exec, I always get error like this, but I
still dont't know what is a problem:
Traceback (most recent call last):
File
...:::JA:::... wrote:
Hello,
After my program read and translate this code:
koristi os,sys;
ispisi 'bok kaj ima';
into the:
import os,sys;
print 'bok kaj ima';
and when it run this code with exec, I always get error like this, but I
still dont't know what is a problem:
On Sat, 21 Jul 2007 16:31:38 -0400, Steve Holden wrote:
I'm afraid I don't understand this question. If you are talking about
the indentation of the code, if you don't want indentation you will have
to use braces - { and } - to indicate the nesting structure of your program.
Oh my, teasing
I'm using code.Interactive console but it doesn't work correctly
with non-ascii characters. I think it boils down to this problem:
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on win32
Type help, copyright, credits or license for more information.
print uä
ä
exec
Thomas Heller schrieb:
I'm using code.Interactive console but it doesn't work correctly
with non-ascii characters. I think it boils down to this problem:
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
Type help, copyright, credits or license for more
On 23/06/2006 9:06 PM, Thomas Heller wrote:
I'm using code.Interactive console but it doesn't work correctly
with non-ascii characters. I think it boils down to this problem:
Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310 32 bit (Intel)] on
win32
Type help, copyright, credits or
TPJ wrote:
(...) Even allowing for the
difficulties you've already experienced, it's nearly always better in
practical cases to use assignment to the keys of a dictionary. Then no
exec is required, and you have direct control over your own namespace.
Well... Is this a sugestion, that
I have the following code:
---
def f():
def g():
a = 'a' # marked line 1
exec 'a = b' in globals(), locals()
print g: a =, a
a = 'A' # marked line 2
exec 'a = B' in globals(), locals()
print f: a =, a
g()
f()
TPJ wrote:
I have the following code:
---
def f():
def g():
a = 'a' # marked line 1
exec 'a = b' in globals(), locals()
print g: a =, a
a = 'A' # marked line 2
exec 'a = B' in globals(), locals()
print
TPJ wrote:
I have the following code:
---
def f():
def g():
a = 'a' # marked line 1
exec 'a = b' in globals(), locals()
print g: a =, a
a = 'A' # marked line 2
exec 'a = B' in globals(), locals()
print f:
Use the exec statement without the in-clause to get the desired effect:
def f():
... a = a
... exec a = 'B'
... print a
...
f()
B
snip
Well... I *do* realize that. But this is *not* my problem. I have a
function with another nested one. If I used exec ... instead of exec
snip
So when you exec 'a = B' in globals(), locals() you might think you
were changing the local namespace. In fact you are changing a copy of
the local namespace:
snip
Well, that explains much, but not all that I want to be explained. Why?
Because now I understand, that by invoking
exec a
Op 2005-12-16, Peter Otten schreef [EMAIL PROTECTED]:
Antoon Pardon wrote:
I'm using PLY. The assign function is a dumbded down version
of a production function that will be called during the parsing
of a config file. Each time a line of the form:
var = val
is encounterd I do
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct = {'config':config, 'assign':assign}
exec assign() in dct
print config.Start
foo()
When I execute this I get the
Antoon Pardon wrote:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct = {'config':config, 'assign':assign}
exec assign() in dct
print config.Start
foo()
Antoon Pardon wrote:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct = {'config':config, 'assign':assign}
exec assign() in dct
print config.Start
foo()
Antoon Pardon wrote:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct = {'config':config, 'assign':assign}
exec assign() in dct
print config.Start
foo()
When
Op 2005-12-16, Peter Otten schreef [EMAIL PROTECTED]:
Antoon Pardon wrote:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct = {'config':config, 'assign':assign}
Op 2005-12-16, Larry Bates schreef [EMAIL PROTECTED]:
Antoon Pardon wrote:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct = {'config':config, 'assign':assign}
Antoon Pardon wrote:
And from the documentation
from exec I get the impression you can use it so that a function
will have temporarily a different reference to global namespace.
That impression confuses two things:
(1) A function object carries a global namespace with it. That namespace is
Antoon Pardon wrote:
Op 2005-12-16, Larry Bates schreef [EMAIL PROTECTED]:
Antoon Pardon wrote:
I have the following little piece of code:
class Cfg:pass
#config = Cfg()
def assign():
setattr(config, 'Start' , [13, 26, 29, 34])
def foo():
config = Cfg()
dct =
Peter Otten wrote:
If you could provide a function with a different namespace when it's called,
e. g
f() in namespace
would look up its globals in namespace, that might be an interesting concept
but it's not how Python works.
Peter
It does seem like an interesting concept, so I
39 matches
Mail list logo