from random import randint from datetime import datetime import json # constant settings a = json.load(open('settings.json', 'r')) sens = len(a['sensor_ports']) fileName = a["file_name"] numberofsensors = len(a['sensor_ports']) for i in range(1000): f = open(fileName, 'a') f.write(", ".join([datetime.now().strftime('%H:%M:%S')] + [str(randint(1, 1000)) for j in range(numberofsensors)]) + '\n') f.close()