Re: problem with exec and locals()

2008-07-11 Thread Gabriel Genellina
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 >    

Re: problem with exec and locals()

2008-07-11 Thread Peter Otten
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

Re: problem with exec and locals()

2008-07-10 Thread Uwe Schmitt
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

Re: problem with exec and locals()

2008-07-01 Thread Mel
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

problem with exec and locals()

2008-07-01 Thread rocksportrocker
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

Re: Problem with exec

2008-03-14 Thread Justus Schwabedal
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() >>

Re: Problem with exec

2008-03-13 Thread alitosis
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 "

Problem with exec

2008-03-13 Thread Justus Schwabedal
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 execB

Problem with exec

2008-03-12 Thread Justus Schwabedal
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 execB

Re: problem with exec

2007-07-23 Thread vedrandekovic
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 qu

Re: problem with exec

2007-07-23 Thread Gabriel Genellina
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 in

Re: problem with exec

2007-07-22 Thread Steve Holden
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 afrai

Re: problem with exec

2007-07-22 Thread Steven D'Aprano
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 questio

Re: problem with exec

2007-07-22 Thread vedrandekovic
> 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

Re: problem with exec

2007-07-22 Thread Steve Holden
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==9

Re: problem with exec

2007-07-22 Thread Steven D'Aprano
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'

Re: problem with exec

2007-07-22 Thread vedrandekovic
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"

Re: problem with exec

2007-07-21 Thread Steven D'Aprano
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, teasin

Re: problem with exec

2007-07-21 Thread Steve Holden
...:::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 pro

problem with exec

2007-07-21 Thread ...:::JA:::...
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 "

Re: Unicode problem with exec

2006-06-23 Thread John Machin
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", "cre

Re: Unicode problem with exec

2006-06-23 Thread Diez B. Roggisch
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" fo

Unicode problem with exec

2006-06-23 Thread Thomas Heller
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"ä" ä

Re: A problem with exec statement

2006-04-15 Thread Peter Otten
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, t

Re: A problem with exec statement

2006-04-14 Thread TPJ
> > 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: > Well, that explains much, but not all that I want to be explained. Why? Because now I understand, that by invoking exec "a =

Re: A problem with exec statement

2006-04-14 Thread TPJ
> Use the exec statement without the in-clause to get the desired effect: > > >>> def f(): > ... a = "a" > ... exec "a = 'B'" > ... print a > ... > >>> f() > B > Well... I *do* realize that. But this is *not* my problem. I have a function with another nested one. If I used "exec ..."

Re: A problem with exec statement

2006-04-14 Thread Steve Holden
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(), loc

Re: A problem with exec statement

2006-04-14 Thread Peter Otten
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(), lo

A problem with exec statement

2006-04-13 Thread TPJ
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(

Re: Problem with exec

2005-12-19 Thread Antoon Pardon
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 encounte

Re: Problem with exec

2005-12-16 Thread Michael Spencer
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 concep

Re: Problem with exec

2005-12-16 Thread Peter Otten
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(): >>> confi

Re: Problem with exec

2005-12-16 Thread Peter Otten
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

Re: Problem with exec

2005-12-16 Thread Antoon Pardon
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':conf

Re: Problem with exec

2005-12-16 Thread Antoon Pardon
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':co

Re: Problem with exec

2005-12-16 Thread Fredrik Lundh
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

Re: Problem with exec

2005-12-16 Thread Peter Otten
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.Sta

Re: Problem with exec

2005-12-16 Thread Peter Otten
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.Sta

Re: Problem with exec

2005-12-16 Thread Larry Bates
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.Star

Problem with exec

2005-12-16 Thread Antoon Pardon
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 follow