Space Python Loading Python…

Telemetry from CSV

Write the codeMedium 2 stages

The feed parser from "Parse the whole feed" still reads two lines somebody pasted into the program. The ground station now delivers a proper export, telemetry.csv, with a header row, and it changes every few seconds.

Read the file itself, with the module made for it, then pick out the hottest reading.

Replace the old parser and its feed string: open telemetry.csv with newline="", loop over csv.DictReader(csv_file), and print each row in the same format as before:

09:30:05 ENG-2: 412.5 C
09:30:05 TANK-1: 78.3 %
09:30:10 CABIN: 101.2 kPa
09:30:10 ENG-2: 415.0 C
09:30:15 ENG-1: 455.2 C
09:30:15 ENG-3: 98.6 C
09:30:15 TANK-1: 78.1 %

Each row is a dict keyed by the header: row["sensor"], row["value"] and so on. Leave the lines that write the file as they are.

Every row from the file
With the csv module

Finish stage 1 to unlock this stage.

While you loop, keep the hottest reading in degrees Celsius, unit C, in hottest, and print it after the readings:

Hottest: ENG-1 455.2 C at 09:30:15

Compare float(row["value"]), not the text: as strings, "98.6" comes after "455.2".

The hottest temperature
You're not logged in, so your progress is kept in this browser only. Log in to save it, and to use hints and solutions.

Hints

Import System Modules

import-system-modules.py
# A module is a toolbox someone else already built and tested for you

# Plain import brings in the whole module
import sys
import platform
import math

# from ... import brings in just one tool
from math import sqrt

# as gives a module a shorter nickname
import random as rng

# With a plain import: module name, a dot, then the tool
print("Python version:", platform.python_version())
print("Running on:", platform.system())
print("Python lives at:", sys.executable)

# math carries constants you would not want to type from memory
radius_km = 6371
print("Earth circumference:", round(2 * math.pi * radius_km), "km")

# sqrt arrived on its own, so it needs no dot in front
print("Square root of 9:", sqrt(9))

# rng is simply a nickname for random
print("Random sol of the Martian year:", rng.randint(1, 687))
Open the full example
script.py
PythonLn 1, Col 1Spaces: 4
Loading the Python environment…

Separate arguments with commas. They're passed on every Run as sys.argv[1:].