I split my data-logger script into two files. logger.py opens the serial port and starts logging at the bottom of the file; plot.py does import logger to reuse one parsing function. Now running plot.py opens the serial port and starts logging, which I did not want.
Tutorials put such code under if __name__ == "__main__": without explaining much. What is __name__, who sets it, and are there cases where leaving the guard out causes real failures rather than just unwanted output?




