What is the best way to get this block of code to run when I import main.py rather than run it?
#main.py
if __name__ == '__main__':
#Do something interesting.
#Do something to have the interesting code run after importing the file.
import main.py
main.__main__() # wrong of course.
Put that code into a function, and call it inside
if.Or simply don’t use
ifat all.