0

Say I have a file x.py and another file y.py. In a C program , the preprocessor would simply copy the contents of x and replace #include x.py with them, and similarly with y.

Python does not preprocess like that - there is no #include; import works very differently from simple text substitution/replacement, which is what I want (the end result should be one single file that has everything, but it isn't practical to work with such a file during development).

What I'm currently using is essentially something like : cat globals.py functions.py main.py > final.py

user426
  • 213
  • 2
  • 9
  • 1
    *import works very differently* - What do you mean by this ? – Ram Aug 13 '21 at 04:07
  • @Ram I simply mean that `import != include`. – user426 Aug 13 '21 at 04:08
  • I think this really boils down to some fundamental differences between the two languages. C is compiled and the purpose of said preprocessing step is to facilitate compilation. Python on the other hand is an interpreted language and the import statement brings a module that was previously out of scope into scope. There isn't a reason to combine everything into a single file in Python AFAIK but I believe you could just cat the files together in a pinch. People discussed it [here](https://stackoverflow.com/questions/21163345/how-to-combine-and-get-a-single-python-file-by-resolving-the-imports). – 0x263A Aug 13 '21 at 05:13

0 Answers0