If the only thing you want is to use the {identifier} syntax, without having to repeat `identifier` more than once, the simplest alternative is probably:
>>> package = "foo"
>>> whatever = "bar"
>>> "Enjoy {package}".format(**locals())
'Enjoy foo'
(disclaimer: I wouldn't actually use locals() like this in real code)Also, if this thing is truly mangling bytecode, it's not portable between different python versions
But i'm not quite sure about that: I only skimmed the codebase, and that works seems to be done by interpy_untokenize, which boils down to some string mangling
Also, having expressions (or worse, statements... like it would be in ruby since there's no difference there) evaluated when evaluating a string is quite bad (this is not Haskell, and thus we cannot have guarantees that side effects won't happen)
Nice hack, btw
Also, if this thing is truly mangling bytecode, it's not portable between
different python versions [...] seems to be done by interpy_untokenize,
which boils down to some string mangling
It uses the Python file encoding property ("# coding: foobar") to rewrite the source code, not the bytecode, and they refer to pyxl as an inspiration.For a good explanation, see https://github.com/dropbox/pyxl