Re: From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-04-06 Thread Gregory Ewing
adam.pre...@gmail.com wrote: I've figured from this that I could do most variable access by just generating LOAD/STORE_NAME and the FAST is an (important) optimization. Yes, that's possible, although access to intermediate scopes (i.e. nonlocal) will need something else. An important exceptio

Re: From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-04-05 Thread adam . preble
On Friday, April 5, 2019 at 5:54:42 PM UTC-5, Gregory Ewing wrote: > But when compiling a class body, it uses a dict to hold the > locals, and generates LOAD_NAME and STORE_NAME opcodes to > access it. > > These opcodes actually date from very early versions of > Python, when locals were always ke

Re: From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-04-05 Thread Gregory Ewing
adam.pre...@gmail.com wrote: Something I don't really understand from a code generation perspective is the switch over to STORE_NAME for class methods. That's because, in this particular situation, the locals are being kept in a dict instead of an array. When compiling an ordinary function, th

Re: From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-04-04 Thread adam . preble
On Thursday, April 4, 2019 at 1:17:02 PM UTC-5, adam@gmail.com wrote: > Thanks for the response. I was meaning to write back earlier, but I've been > spending my free Python time in the evenings reimplementing what I'm doing to > work more correctly. I'm guessin

Re: From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-04-04 Thread adam . preble
pending my free Python time in the evenings reimplementing what I'm doing to work more correctly. I'm guessing before the code object representing the class body gets run, __build_class__ is establishing various dunders such as __name__, __qual_name__, and __module__. I haven't fully pe

Re: From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-03-31 Thread Gregory Ewing
adam.pre...@gmail.com wrote: What is the plumbing taking the result of that code object over to this proxy? I'm assuming __build_class__ runs that code object and then starts looking for new names and see to create this. Is this mapping proxy the important thing for carrying the m

From parsing a class to code object to class to mappingproxy to object (oh my!)

2019-03-31 Thread adam . preble
could more readily poke it with a stick. I understand LOAD_BUILD_CLASS will invoke builtins.__build_class__(). By the way, why the special opcode for that? Anyways, it takes that code object, which looks to be particularly special. Note that I'm inserting some newlines and extra junk for sa

Re: retrieve source code from code object as returned by compile()

2014-04-25 Thread Gregory Ewing
Amirouche Boubekki wrote: in python3, I do inspect.getsource(object) [doc ], I don't know the limitations. The limitation relevant here is that it requires the original source file to be present. :-) -- Greg -- https://mail.pyt

Re: retrieve source code from code object as returned by compile()

2014-04-25 Thread Amirouche Boubekki
n to submit it to a database, instead of stored procedures, but I have the source of the code. It can also be used to retrieve the ast. 2014-04-25 4:50 GMT+02:00 Justin Ezequiel : > On Thursday, April 24, 2014 1:53:38 PM UTC+8, Gregory Ewing wrote: > > Alternatively you could create a

Re: retrieve source code from code object as returned by compile()

2014-04-24 Thread Justin Ezequiel
On Thursday, April 24, 2014 1:53:38 PM UTC+8, Gregory Ewing wrote: > Alternatively you could create a .pyc file out of the code > object and then use Easy Python Decompiler on that. The > following snippet of code should do that: > > (Taken from: > > http://stackoverflow.

Re: retrieve source code from code object as returned by compile()

2014-04-23 Thread Gregory Ewing
Justin Ezequiel wrote: Using "Easy Python Decompiler" I am able to get the source for the imported modules. Using "Resources Viewer" from PlexData and some code I am able to retrieve the code object. I am however stumped as to how to retrieve the source from this code o

retrieve source code from code object as returned by compile()

2014-04-23 Thread Justin Ezequiel
iewer" from PlexData and some code I am able to retrieve the code object. I am however stumped as to how to retrieve the source from this code object. PythonWin 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit (Intel)] on win32. Portions Copyright 1994-2008 Mark Hammond - see &

Re: [Q] How to exec code object with local variables specified?

2012-09-21 Thread 88888 Dihedral
Makoto Kuwata於 2012年9月20日星期四UTC+8下午7時27分40秒寫道: > Hi, > > > > Is it possible to run code object with local variables specified? > > I'm trying the following code but not work: > > > > def fn(): > >x = 1 > >y = 2 >

Re: [Q] How to exec code object with local variables specified?

2012-09-21 Thread Peter Otten
Makoto Kuwata wrote: > On Thu, Sep 20, 2012 at 10:15 PM, Peter Otten <__pete...@web.de> wrote: >> >>>>> loc = {} >>>>> exec("x = 1; y = 2", globals(), loc) >>>>> loc >> {'y': 2, 'x': 1} >> >&

Re: [Q] How to exec code object with local variables specified?

2012-09-20 Thread Terry Reedy
On 9/20/2012 7:27 AM, Makoto Kuwata wrote: Is it possible to run code object with local variables specified? In the way you mean that, no. I'm trying the following code but not work: def fn(): x = 1 y = 2 localvars = {'x': 0} exec(fn.fun

Re: [Q] How to exec code object with local variables specified?

2012-09-20 Thread Makoto Kuwata
On Thu, Sep 20, 2012 at 10:15 PM, Peter Otten <__pete...@web.de> wrote: > >>>> loc = {} >>>> exec("x = 1; y = 2", globals(), loc) >>>> loc > {'y': 2, 'x': 1} > > However, this won't work with the cod

Re: [Q] How to exec code object with local variables specified?

2012-09-20 Thread Peter Otten
Makoto Kuwata wrote: > Is it possible to run code object with local variables specified? > I'm trying the following code but not work: > > def fn(): >x = 1 >y = 2 > localvars = {'x': 0} > exec(fn.func_code, globals(), localvars)

[Q] How to exec code object with local variables specified?

2012-09-20 Thread Makoto Kuwata
Hi, Is it possible to run code object with local variables specified? I'm trying the following code but not work: def fn(): x = 1 y = 2 localvars = {'x': 0} exec(fn.func_code, globals(), localvars) print(localvars) ## what I expected is:

Re: How does a function know the docstring of its code object?

2011-09-15 Thread Arnaud Delobelle
On 15 September 2011 16:17, Ian Kelly wrote: > On Thu, Sep 15, 2011 at 5:10 AM, Arnaud Delobelle wrote: >> Hi all, >> >> You can do: >> >> def foo(): >>    "foodoc" >>    pass >> >> function = type(lambda:0) >> foo2 = function(foo.__code__, globals()) >> assert foo2.__doc__ == "foodoc" >> >> I am

Re: How does a function know the docstring of its code object?

2011-09-15 Thread Ian Kelly
On Thu, Sep 15, 2011 at 5:10 AM, Arnaud Delobelle wrote: > Hi all, > > You can do: > > def foo(): >    "foodoc" >    pass > > function = type(lambda:0) > foo2 = function(foo.__code__, globals()) > assert foo2.__doc__ == "foodoc" > > I am wondering how the function constructor knows that foo.__code

How does a function know the docstring of its code object?

2011-09-15 Thread Arnaud Delobelle
Hi all, You can do: def foo(): "foodoc" pass function = type(lambda:0) foo2 = function(foo.__code__, globals()) assert foo2.__doc__ == "foodoc" I am wondering how the function constructor knows that foo.__code__ has a docstring. I can see that foo.__code__.co_consts == ('foodoc',)

Re: Getting a module's code object

2011-08-25 Thread Arnaud Delobelle
On 25 August 2011 16:07, Peter Otten <__pete...@web.de> wrote: > Arnaud Delobelle wrote: > >> In Python 3, a function f's code object can be accessed via f.__code__. >> >> I'm interested in getting a module's code object, [...] > > Taken from

Re: Getting a module's code object

2011-08-25 Thread Peter Otten
Arnaud Delobelle wrote: > In Python 3, a function f's code object can be accessed via f.__code__. > > I'm interested in getting a module's code object, i.e. the code that > is executed when the module is run. I don't think it's accessible via > the module

Getting a module's code object

2011-08-25 Thread Arnaud Delobelle
Hi all, In Python 3, a function f's code object can be accessed via f.__code__. I'm interested in getting a module's code object, i.e. the code that is executed when the module is run. I don't think it's accessible via the module object itself (although I would be g

Re: code object differences between 2.7 and 3.3a

2011-08-11 Thread Ned Deily
In article , Eric Snow wrote: > Specifically, I am wondering why there is a difference for co_names. This is not an answer to your question but, as a metapoint, in my experience it is usually faster and often more reliable to try to answer questions like this yourself using the tools that the

code object differences between 2.7 and 3.3a

2011-08-10 Thread Eric Snow
Specifically, I am wondering why there is a difference for co_names. Here is a function that exercises the different code object pieces[1]: def g(y=5): a = 7 def f(x, w=y, z=4, *args, **kwargs): b = a c = global_x return f f1 = g() Here are the results for 2.7: >>

Re: Get "code object" of class

2008-10-11 Thread Okko Willeboordse
Thanks, "Why do you even need the classes code object anyway?" I need to instantiate and use the class in another process. This other process doesn't has access to the py or pyc file holding the m_class (source) code so I can't use pickle. Something like; In the first proc

Re: Get "code object" of class

2008-10-10 Thread Matimus
On Oct 10, 5:50 am, Okko Willeboordse <[EMAIL PROTECTED]> wrote: > To get the "code object" c of my_class I can do; > > c = compile(inspect.getsource(my_class), "

Get "code object" of class

2008-10-10 Thread Okko Willeboordse
To get the "code object" c of my_class I can do; c = compile(inspect.getsource(my_class), "

Re: What is the function to evaluate code object returned byPyParser _SimpleParseString function?

2007-11-21 Thread grbgooglefan
block & not able to execute this function definition which is part of "*codeObject*" returned by Py_CompileString. What should I do to transform this 'code' object to 'callable' or 'function' object, so that I can call it? Please help. Regards. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to access C variables in Python code object generated by Py_C ompileString

2007-11-20 Thread Duncan Booth
"Borse, Ganesh" <[EMAIL PROTECTED]> wrote: > 2) my this code got compiled but when running, I got an error from > Py_CompileString, as below. Why is it so? > File "", line 1 > if ( (size < 1000) & (vol < (0.001 * ADV)) & (prod=="Stock")): > print "OK" ^ > SyntaxError: invalid syntax >

How to access C variables in Python code object generated by Py_C ompileString

2007-11-20 Thread Borse, Ganesh
;NOK" **/ char szExpr[1024]; memset(szExpr,'\0',sizeof(szExpr)); sprintf(szExpr," if ( (size < 1000) & (vol < (0.001 * ADV)) & (prod==\"Stock\")): print \"OK\" \nelse: print \"NOK\" \n"); // Parse & compile this

RE: How to evaluate the code object returned by PyParser_SimplePa rseString function?

2007-11-16 Thread Borse, Ganesh
Thanks this is helpful. -Original Message- From: Gabriel Genellina [mailto:[EMAIL PROTECTED] Sent: 15 November 2007 12:26 To: python-list@python.org Subject: Re: How to evaluate the code object returned by PyParser_SimplePa rseString function? En Wed, 14 Nov 2007 23:20:14 -0300, Borse

Re: What is the function to evaluate code object returned byPyParser _SimpleParseString function?

2007-11-15 Thread Terry Reedy
uot; I am rather sure that the filename param is the same as for the Python-level builtin function compile: compile( string, filename, kind[, flags[, dont_inherit]]) Compile the string into a code object. Code objects can be executed by an exec statement or evaluated by a call to eval(). The fil

What is the function to evaluate code object returned by PyParser _SimpleParseString function?

2007-11-15 Thread Borse, Ganesh
er 2007 07:51 To: python-list@python.org Subject: Re: How to use the evaluate the code object returned by PyParser_Simp leParseString function? En Wed, 14 Nov 2007 06:48:41 -0300, Borse, Ganesh <[EMAIL PROTECTED]> escribió: > `struct _node* PyParser_SimpleParseString(char *str, int start)

Re: How to evaluate the code object returned by PyParser_SimplePa rseString function?

2007-11-14 Thread Gabriel Genellina
En Wed, 14 Nov 2007 23:20:14 -0300, Borse, Ganesh <[EMAIL PROTECTED]> escribió: > Py_CompileString takes the source code from file, isn't it? > As can be seen from the syntax of this function: PyObject* > Py_CompileString(char *str, char *filename, int start) > > I want to parse the code which

RE: How to evaluate the code object returned by PyParser_SimplePa rseString function?

2007-11-14 Thread Borse, Ganesh
ROTECTED] Sent: 15 November 2007 07:51 To: python-list@python.org Subject: Re: How to use the evaluate the code object returned by PyParser_Simp leParseString function? En Wed, 14 Nov 2007 06:48:41 -0300, Borse, Ganesh <[EMAIL PROTECTED]> escribió: > `struct _node* PyParser_SimplePars

Re: How to use the evaluate the code object returned by PyParser_Simp leParseString function?

2007-11-14 Thread Gabriel Genellina
En Wed, 14 Nov 2007 06:48:41 -0300, Borse, Ganesh <[EMAIL PROTECTED]> escribió: > `struct _node* PyParser_SimpleParseString(char *str, int start)' > Parse Python source code from STR using the start token START. The > result can be used to create a code object wh

How to use the evaluate the code object returned by PyParser_Simp leParseString function?

2007-11-14 Thread Borse, Ganesh
m STR using the start token START. The result can be used to create a code object which can be evaluated efficiently. This is useful if a code fragment must be evaluated many times. I have exactly same requirement. I have dynamic expressions loaded from database at startup in

Re: Converting _node* to a Code object?

2007-04-01 Thread Brendon Costa
Gabriel Genellina wrote: > En Sun, 01 Apr 2007 01:35:59 -0300, Brendon Costa <[EMAIL PROTECTED]> > escribió: > >> How do i convert a _node* object returned from: >> PyParser_SimpleParseStringFlagsFilename() >> >> into a code obje

Re: Converting _node* to a Code object?

2007-04-01 Thread Gabriel Genellina
En Sun, 01 Apr 2007 01:35:59 -0300, Brendon Costa <[EMAIL PROTECTED]> escribió: > How do i convert a _node* object returned from: > PyParser_SimpleParseStringFlagsFilename() > > into a code object i can use as a module to import with: > PyImport_ExecCodeModule() Using Py

Converting _node* to a Code object?

2007-03-31 Thread Brendon Costa
gsFilename() into a code object i can use as a module to import with: PyImport_ExecCodeModule() I cant seem to find any documentation about this. If you are wondering why i want to do this, then you can read on and maybe there is a much better way to achieve what i am after. Thanks, Brendon

Re: code-object

2007-02-20 Thread Steven D'Aprano
On Tue, 20 Feb 2007 20:39:43 -0500, LG wrote: > Hi, All, > >>>>code = compile('print "hello everyone, how are you? "', '', > 'exec') >>>>exec code > hello everyone, how are you? >>>>print code > ",

Re: code-object

2007-02-20 Thread Gabriel Genellina
En Tue, 20 Feb 2007 22:39:43 -0300, LG <[EMAIL PROTECTED]> escribió: >>>> code = compile('print "hello everyone, how are you? "', '', > 'exec') >>>> exec code > hello everyone, how are you? >>>> print code

code-object

2007-02-20 Thread LG
Hi, All, >>>code = compile('print "hello everyone, how are you? "', '', 'exec') >>>exec code hello everyone, how are you? >>>print code ", line 1> how to print the code object ? like the one on .pyc Regards LG -- http://mail.python.org/mailman/listinfo/python-list

Re: Q: How to generate code object from bytecode?

2006-12-26 Thread kwatch
Thanks Fredrik and Carsten, I'll try marshal module. > * Your code snippet is a statement, actually, a suite of statements. You > need to exec it, not eval it. > * You seem to think that eval'ing or exec'ing a code object will > magically capture its output stream. It

Re: Q: How to generate code object from bytecode?

2006-12-26 Thread Carsten Haese
On Tue, 2006-12-26 at 14:48 -0500, Carsten Haese wrote: > * Code objects come in two flavors: statements and expressions. > * exec can execute a 'statement' flavored code object. > * eval can evaluate an 'expression' flavored code object. > * Your code snippet is a

Re: Q: How to generate code object from bytecode?

2006-12-26 Thread Carsten Haese
On Tue, 2006-12-26 at 11:15 -0800, [EMAIL PROTECTED] wrote: > Hi, > > It is possible to get bytecode from code object. > Reversely, is it possible to create code object from bytecode? > > ex. > ## python code (not a module) > pycode = '''\ > print

Re: Q: How to generate code object from bytecode?

2006-12-26 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > It is possible to get bytecode from code object. > Reversely, is it possible to create code object from bytecode? > > ex. > ## python code (not a module) > pycode = '''\ > print "\n" > for item in

Q: How to generate code object from bytecode?

2006-12-26 Thread kwatch
Hi, It is possible to get bytecode from code object. Reversely, is it possible to create code object from bytecode? ex. ## python code (not a module) pycode = '''\ print "\n" for item in items: print "%s\n" % item print "\n"

Re: python compile code object -- reverse how to

2006-07-19 Thread leo
Hi, all, i mean to convert 'c\000\000\000\000\001\000\000\000s\017\000\000\00 > 0\177\000\000\177\002\000d\000\000GHd\001\000S(\00 > 2\000\000\000s\005\000\000\000helloN(\000\000\000\ > 000(\000\000\000\000s\010\000\000\000

python compile code object -- reverse how to

2006-07-19 Thread leo
Hi, following is the python scripts: import marshal script = """ print 'hello' """ code = compile(script, "