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

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 "

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

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