I have a python program named communication.py to receive data from Arduino as below:
import serial
if __name__ == '__main__':
ser = serial.Serial('COM5', 9600, timeout=1)
ser.reset_input_buffer()
while True:
if ser.in_waiting > 0:
line = ser.readline().decode('utf-8').rstrip()
if (line == "0.0"):
data = (0,0)
print(data)
the program can print variable values correctly but in another python named print.py program, I tried to export the variable named data in this way
from communication import data
print(data)
but that doesn't work because the python.py program doesn't recognize the variable named "data". Does this error have something to do with the while loop?