Re: [Pyparsing] DSL using pyparsing
Brought to you by:
ptmcg
From: Paul M. <pt...@au...> - 2009-06-12 14:19:05
|
> -----Original Message----- > From: Asim Malik [mailto:as...@ho...] > Sent: Friday, June 12, 2009 6:31 AM > To: pt...@au...; pyp...@li... > Subject: RE: [Pyparsing] DSL using pyparsing > > So is there a way for the import hook to somehow inject the import > statements, when executing the code? Or does my generated code have to > explicitly declare each import statement? > Have your import hook inject the necessary import statements at the top of the generated code: generated_code = """from Color import Color %s""" % data Here I put your Color class in a file named Color.py. Now when I run the script testColor.py, which contains this code: import Colors import abc print abc.c I get: from Color import Color c = Color(255, 0, 255) cols Now the last step is for you to convert your assignment to generated_code to use a pyparsing expression, and call transformString on the content of the file (in your variable 'data'). -- Paul |