When I connect my Arduino Uno to my computer via USB, it immediately goes into the setup() and loop() functions as expected. I know I could add a conditional into loop() to control how often it executes, but for my purposes, I would really like to control the arduino with a python script on my computer.
To be specific, I am using an ultrasonic sensor and using pyserial to read in measurements from the serial port, but I would prefer for the arduino to wait until my Python script has finished some tasks before starting to print the values to the serial monitor.
Your arduino loop() will continue to do its thing, and then, when it receives some command like 'r' or "read" or whatever, it prints out the data. Depending on what you want, it could also be something like "start" and "stop" which toggles a flag to print data. "start" toggles the flag to true, "stop" toggles the flag to false...
I would recommend single letter commands since reading a single char is easier than dealing with char arrays, especially if you are new to this.