Re: func_code vs. string problem

2005-04-24 Thread Filip Dreger
Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w wiadomosci news:[EMAIL PROTECTED] > Any reason you can't define it like: > > class actor(object): > def __init__(self): > self.roles = [] > def act(self): > for role_func in self.roles: > role_func(self)

Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote: Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w wiadomosci news:[EMAIL PROTECTED] See the documentation: http://docs.python.org/ref/dynamic-features.html """The eval(), execfile(), and input() functions and the exec statement do not have access to the full environme

Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger
Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w wiadomosci news:[EMAIL PROTECTED] > See the documentation: > > http://docs.python.org/ref/dynamic-features.html > > """The eval(), execfile(), and input() functions and the exec > statement do not have access to the full environment for r

Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote: If I had a magic function 'exec in current scope' I would implement it like this: class actor: def __init__(): self.roles=[] def act(): for i in self.roles: exec i in current scope then the roles would simply be functions defined in any importable file. For

Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger
Uzytkownik "Steven Bethard" <[EMAIL PROTECTED]> napisal w wiadomosci news:[EMAIL PROTECTED] > Filip Dreger wrote: >> I am trying to find a way of executing functions without creating a >> nested scope, so they can share local and global namespace (even if >> they are declared in some other modu

Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote: I am trying to find a way of executing functions without creating a nested scope, so they can share local and global namespace (even if they are declared in some other module). Why? Can you explain what the use case is? STeVe -- http://mail.python.org/mailman/listinfo/python-

Re: func_code vs. string problem

2005-04-23 Thread Steven Bethard
Filip Dreger wrote: Each function has a func_code property that is suposed to contain the pure bytecode of the function. All the context (including reference to relevant namespaces) is stored in different fields of the function object. Since 'exec' is able to execute any string or bytecode in th

Re: func_code vs. string problem

2005-04-23 Thread Filip Dreger
I came up with a simpler description of the problem. It's all in the simple source: # we define 'print b' in three different ways: as a string, # a bytecode and a function string="print b" code=compile(string,'string','exec') def function(): print b # now we make functions that test if it is

func_code vs. string problem

2005-04-23 Thread Filip Dreger
Each function has a func_code property that is suposed to contain the pure bytecode of the function. All the context (including reference to relevant namespaces) is stored in different fields of the function object. Since 'exec' is able to execute any string or bytecode in the current scope, it