EDIT: Solved, thanks everyone!
What I would like to be able to do in simple terms is take user input from one programming language, convert it into another programming language and have it compiled automatically. 
For example (simplified and not precisely what I want to do but along similar lines):
1) Write a python script, userData = raw_input("blah blah blah, example, example")
2) if userData == "blah blah blah, example, example", serialize to a text file called "example.cpp" and put in some predetermined data which is based on the user's input (written in C++ form, though represented as a string in python script). For simplification this predetermined data will be called predeterminedData.
3) The extent of predeterminedData will be essentially a cout << "this is a different message to before" << endl;
4) The compiler (g++/gcc) compiles this automatically and the overall program structure calls the newly created executable file.
If someone could help point me toward the topic/topics I should read up on to be able to achieve this - if it's possible - that'd be fantastic.
Edit: I've made a classic mistake I think. In an attempt to not be accused of asking other people to do my "homework" for me I've been too vague and consequently misleading. Thank you for the responses so far but perhaps now I should be more specific. It isn't particularly python nor c++ specific but I will explain beneath. I apologize for not being more explicit before.
What I actually want to achieve is quite simple. I want to use user input from one programming language (python, c++, java) and have it create a Lilypond script which will automatically compile and create a midi file.
So for example:
1) User is asked to enter alphabetically a series of notes: e.g. "C" then "E" then "F", so on and so on.
2) These "notes" are checked by a control loop statement and a string is created in the Lilypond script and serialized to a file which is compatible with its compiler (example.ly)
3) This file is automatically compiled by the Lilypond compiler and creates a midi file (example.midi)
4) Later in the program this example.midi can be called on and played back because of this creation process. It would not have existed prior to this creation.
To me it sounds like you just want to write a user interface for interactive creation of lilypond files.
I don't see what all this has to do with compilation. Your python script will need to write a file in lilypond notation and afterwards your script needs to call lilypond on that file (e.g. with os.system). You could even skip writing to a file and just pipe the output to stdin which lilypond can also read.
Automatic compiling between languages