Peter Otten wrote: > You could automatically convert from a custom format like that in your > original post: > > import re > > _lookup = { > "[[": "{", > "]]": "}", > "{": "{{", > "}": "}}", > > } > > def _substitute(m): > return _lookup[m.group()] > > def custom_format(template, *args, **kw): > return (re.compile(r"\[\[|]]|\{|\}") > .sub(_substitute, template) > .format(*args, **kw)) > > code = "class [[0]]Model { public bool IsModel(){ return a[42] || true; } }" > print custom_format(code, "My")
Nice! I didn't think of that. I guess I could get some additional performance by taking the re.compile step out of the function. Thanks for the tip! AK AK -- http://mail.python.org/mailman/listinfo/python-list