I’m writing Python 3 code and for some reason I want to run everything just in memory and save no files on disk. I managed to solve almost all of my problems so far by reading answers here, but I’m stuck on these lines:
>>> code = compile(source, filename, 'exec')
>>> exec code in module.__dict__
I don’t really understand what the second line does, since I have “in” connected with loops and testing whether something is in some set or not which is not this case.
So, what does the second line do? And what is its Python 3 equivalent since in py3 is exec function, not keyword?
means execute the commands in the file or string called ‘code’, taking global and local variables referred to in ‘code’ from
module.__dict__and storing local and global variables created in ‘code’ into the dictionarymodule.__dict__See http://docs.python.org/reference/simple_stmts.html#exec
Eg:
Eg2: