Possible Duplicate:
How to concatenate multiple Python source files into a single file?
Is there a Python “pre-interpreter” to take as input a .py module containing imports and expand it so it can be run inline in an interpreter session on the command line or Telnet session? Imports of built-ins or installed modules are OK to keep, but I’d like the pre-interpreter to expand my own modules. This way, I can avoid an install while still employing modular programming techniques. For example, if I write these two modules:
myprint.py:
from math import pi
def print_pi():
print "{0:6f}".format(pi)
main.py:
from myprint import print_pi
print_pi()
Running the pre-interpreter on main.py, the output would be:
from math import pi
def print_pi():
print "{0:6f}".format(pi)
print_pi()
Update October 10 2012 22:36 Eastern USA:
Thanks to everyone who responded! My program's runtime host is permanently installed on board a locomotive, from where my program will query and monitor that computer and many other onboard systems. You can correctly predict that this computing environment is safety and mission critical (thus the need for my team’s monitoring software). Installing software in such an environment requires privileges, consumes resources, and imposes a small but real risk to the system. Thus, prudent but weeks-consuming checks have been implemented by the railroad to scrutinize software to be installed, including sign-off by a change-control board. This is the route we had planned for. But if we can eliminate this risk and thereby lessen the formality by running without any installation, that could be an advantage to at least consider. However, we do not want our architecture to be restricted by the non-install requirement, i.e., we don't want to have to write the whole program in one module. From your answers it seems my notion is not possible.