Creating functions programmatically
Anders J. Munch
andersjm at dancontrol.dk
Thu Dec 12 03:31:42 EST 2002
"Michael Hudson" <mwh at python.net> wrote:
> "Anders J. Munch" <andersjm at dancontrol.dk> writes:
>
> > One thing that I don't see how to achieve with exec is control over
> > location in diagnostic messages. Regular Python diagnostics are fine,
> > but file and line should not point to the exec statement in the .py
> > file, but to the appropriate place in the file I'm parsing. I could
> > use something akin to C's #line here, is there any Python equivalent?
>
> One option is to use exec to build the function object, then pick it
> apart and rebuild it using the new module with co_firstline and
> co_filename tweaked to be the correct values.
Good idea, I'll try that.
Thanks,
Anders
More information about the Python-list
mailing list