Well, based on your example, and from what I read from the python manual, it looks like you're looking for macro functionality.
In C/C++ we have the #define instruction which substitues text for other text or a numerical value.
Everytime the 'number' text is encountered in the C/C++ source file, it is replace with 1 when the program is compiled:
#define number 1
cout << number; // print out 1
Everytime the 'foo' text is encountered in the source file, it is replaced with the text "fuzz"
#define foo "fuzz"
cout << foo; // prints out fuzz
I don't know if the functionality is still present (I haven't used this in many years), but you can also have a macro accept a parameter like this:
#define trythis(p) cout << p
So, when the compiler encounters this in the source file::
trythis(4);
It gets translated to this:
cout << 4; // print out 4
The #define instruction doesn't really support multi-line macros. You have to use semicolons:
#define moo int myint;char mychar;cout << "hello"
moo;
Translates to:
int myint;char mychar;cout << "hello";
As far as execution goes, well, you don't need something like exec.
If I have code like this:
#define moo cout << "boo\n";
cout << "Hello\n";
moo
cout << "foo\n";
The compiler replaces 'moo' with 'cout << "boo\n";' during compilation.
So, it would be as if I wrote:
cout << "Hello\n";
cout << "boo\n";
cout << "foo\n";
output:
Hello
boo
foo