Yeah have like a top level function that is like a main, something like this:
def interact(): # Your code which handles all the rest of the functions # For example print('Welcome to this program!') filename = input('Please enter the data source file: ') load_data(filename) ......
And then at the bottom of your script do what you were doing:
if __name__ == '__main__': interact()
if you want to import other files into the program, like mymodule.py, just do this:
from mymodule import *
Alternatively, you can test functions out like this:
if __name__ == "__main__": print test_the_function(123, 456)
When mymodule is imported, the code is run as before, but when we get to the if statement, Python looks to see what name the module has. Since the module is imported, we know it by the name used when importing it, so __name__ is mymodule. Thus, the print statement is never reached.
The beautiful thing about python is that it doesn't work like Cs main(). You just start typing, and you've written your first program. The simplicity of python is what makes it so beautiful, I wouldn't try and compare it with C, it just won't work.
You can also check this website out, if has some useful information about the python main():
https://wiki.python.org/moin/Asking%20for%20Help/Do%20you%20need%20a%20int%20main()%20like%20you%20do%20in%20c%2B%2B
__name__ == '__main__'? Is that not PEP-friendly? Does it not do what you want in certain situations?