I am writing a Python (3.5) module in which I'd like to make use of an existing Python module from an open source project. The module I want to import contains:
- several functions
- a
if __name__ == '__main__':
instruction
but does not contain a def main(args)
function.
Because there is no actual main
function, I cannot import it by means of import module
and use it as module.main()
. Although I did find options to separately execute it as script via the commands os.system()
and subprocess.Popen()
, I am actually looking for a way to make this call an integral part of my code.
I understand I can add the def main()
part myself in the original code, but because it comes from an open source project, I am looking for ways to leave it untouched, so that I don't need to maintain it myself if it gets updated.
I have gone through other very similar questions, such as this and this that could not solve my issue. This answer gives me the feeling what I am trying to do is not trivial.
Is there any way to do this?