def macro(name, filename, source, **identifiers):
 if (not identifiers.has_key('name')):
  identifiers['name'] = name
 source = (source % identifiers)
 codeplace = ('<%s (macro)>' % filename)
 code = compile(source, codeplace, 'exec')
 sm = sys.modules
 tprm = 'twisted.python.reflect.macros'
 if (not sm.has_key(tprm)):
  macros = new.module(tprm)
  sm[tprm] = macros
  macros.count = 0
 macros = sm[tprm]
 macros.count += 1
 macroname = ('macro_' + str(macros.count))
 tprmm = ((tprm + '.') + macroname)
 mymod = new.module(tprmm)
 sys.modules[tprmm] = mymod
 setattr(macros, macroname, mymod)
 dict = mymod.__dict__
 exec code in dict, dict
 return dict[name]

def macro ( name , filename , source , ** identifiers ) : if ( not identifiers . has_key ( 'name' ) ) : identifiers [ 'name' ] = name source = ( source % identifiers ) codeplace = ( '<%s (macro)>' % filename ) code = compile ( source , codeplace , 'exec' ) sm = sys . modules tprm = 'twisted.python.reflect.macros' if ( not sm . has_key ( tprm ) ) : macros = new . module ( tprm ) sm [ tprm ] = macros macros . count = 0 macros = sm [ tprm ] macros . count += 1 macroname = ( 'macro_' + str ( macros . count ) ) tprmm = ( ( tprm + '.' ) + macroname ) mymod = new . module ( tprmm ) sys . modules [ tprmm ] = mymod setattr ( macros , macroname , mymod ) dict = mymod . __dict__ exec code in dict , dict return dict [ name ]
macro this allows you to create macro-like behaviors in python .