By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,363 Members | 2,961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,363 IT Pros & Developers. It's quick & easy.

Using code objects?

P: n/a
Using code objects?

As an OO exercise I have a factory pattern that returns class objects that
each have an "action" method. ClassObj.action() in turn returns a code
object in my recursive process loop.

I create the code objects as a one time step outside my factory pattern and
potential class definitions, then reference them in my potential classes
which seems to work as expected.

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)?

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
.... exp1 = 'foo("#expersion 1#")'
exp2 = 'foo("#expersion 2#")'
obj1 = compile(exp1, 'whatever', 'single')
exec obj1 #expersion 1# obj2 = compile(exp2, 'whatever', 'exec')
exec obj2 #expersion 2#

Thank you,
Lee C
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.