Re: Redo: How to create a function dynamically.

2007-08-22 Thread Peter Otten
Steven W. Orr wrote: > I have this which works: > > #! /usr/bin/python > strfunc = """ > def foo( a ): > print 'a = ', a > """ > exec strfunc > globals()['foo'] = foo > foo( 'Hello' ) > > and this which does not: > > #! /usr/bin/python > import new > strfunc = """ > def foo( a ): > pr

Redo: How to create a function dynamically.

2007-08-22 Thread Steven W. Orr
I have this which works: #! /usr/bin/python strfunc = """ def foo( a ): print 'a = ', a """ exec strfunc globals()['foo'] = foo foo( 'Hello' ) and this which does not: #! /usr/bin/python import new strfunc = """ def foo( a ): print 'a = ', a """ co = compile ( strfunc, '', 'exec' ) exe