Manuel Selva
Manuel Selva

Reputation: 19050

How to split a very large python file?

I am using and maintaining a python script allowing to automatize compilation, execution and performances analysis of some particular applications. The script was quite simple when I created it (it only provided the compilation option) but is now very large (2100 lines, not optimized I agree), quite complex and providing many many different command line options (managing the arguments with argparse is a nightmare, and I am not able to do what I need exactly)

To simplify this, I am planning to split it in several scripts:

These three scripts will need to access to share functions, classes and constants. Regarding this constraint, my question is what is the pyhtonic way to handle this ?

Upvotes: 4

Views: 1205

Answers (1)

musically_ut
musically_ut

Reputation: 34288

You can put the shared code in separate files and then import the file as a module in each script which needs it. To see how the module system in Python works, see the modules documentation for Python 2.7 or the documentation on modules for Python 3.4, depending on which version of Python you are writing code in.

Upvotes: 4

Related Questions