Is there a way to disregard remainder of python script file?

126 Views Asked by At

I am working on a refactoring a Python program. I have copied and pasted some messy source files into new Python modules and I'm working through the module top-to-bottom cleaning it up etc.

As a result, the bottom part of my module is a mess of code fragments and functions that don't necessarily compile - or if they do compile, they crash at runtime or otherwise misbehave.

However I'd like to test the bits of the module that I have worked on as I go by importing the new module into the program where it is to be used and integrating the bits that are done.

Does Python have an equivalent that could be used similarly to PHP's return (when used in the top level of an imported file, outside of a function) or for this case, even better - __halt_compiler, which tells the compiler to disregard the remainder of the file and treat it as if the file stopped there?

This is not the same as exit, because with exit the entire program terminates, whereas I'd like the code that imports the new module to continue executing as if it had encountered the end-of-file at a given point.

0

There are 0 best solutions below