Hi guys, first post here. I hope I'm in the right place, since it seems to be more of a Python issue than a PyQt issue.
I've been trying to import the text generated from the console into a text file with a click.
So every time I do it, I'll notify through the console "Beginning measurement". And the data will be streaming into a text file, then I'd like to tell via the console that it's done. Here's the code:
1. The "measurement complete" printout does not occur
2. I can't restart my measurements unless I re-debug the program, in which the error generated from here is "valueerror: i/o operation on closed file"
I'm a beginner, so anyone who can point me in the right direction here is greatly appreciated.
Thanks!
Vizier87
I've been trying to import the text generated from the console into a text file with a click.
So every time I do it, I'll notify through the console "Beginning measurement". And the data will be streaming into a text file, then I'd like to tell via the console that it's done. Here's the code:
def on_click(self):
clear = lambda: os.system('cls')
clear()
print("Beginning measurement...")
now = datetime.now()
current_time = now.strftime("%Y%m%d-%H%M%S")
parser = argparse.ArgumentParser(description="Read and print data from MAX30102")
parser.add_argument("-r", "--raw", action="store_true",
help="print raw data instead of calculation result")
parser.add_argument("-t", "--time", type=int, default=30,
help="duration in seconds to read from sensor, default 30")
args = parser.parse_args()
with open("/home/pi/Desktop/Output data - " + current_time + self.textbox.text() + ".txt", 'w') as file:
sys.stdout = file
print(self.textbox.text())
hrm = HeartRateMonitor(print_raw=args.raw, print_result=(not args.raw))
hrm.start_sensor()
try:
time.sleep(args.time)
except KeyboardInterrupt:
print('keyboard interrupt detected, exiting...')
hrm.stop_sensor()
file.close()
print("Measurement complete.")
There are two things which happened:1. The "measurement complete" printout does not occur
2. I can't restart my measurements unless I re-debug the program, in which the error generated from here is "valueerror: i/o operation on closed file"
I'm a beginner, so anyone who can point me in the right direction here is greatly appreciated.
Thanks!
Vizier87
