Using code objects?
fredrik at pythonware.com
Wed Jun 22 10:06:02 CEST 2005
> When I create the code objects though, it seems a couple different ways
> work and I'm wondering which is better and why (or is there a more correct
> technique in this situation)?
from where are you getting the source code for those code objects?
from the example below, it sure looks like using callable objects and
argument binding is a "better way" to do it. for the simplest cases,
you can use a plain lambda to delay evaluation:
> The two different ways are illustrated below:
> Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
> [GCC 3.3 20030304 (Apple Computer, Inc. build 1666)]
> Type "help", "copyright", "credits" or "license" for more information.
> >>> def foo(st):
> ... print st
>>> obj1 = lambda: foo("#expression1#")
>>> obj2 = lambda: foo("#expression2#")
More information about the Python-list