Skip to content
Advertisement

Reading part of lines from a txt

I’m trying to read a txt file with informations about time, temperature and humidity, this is the shape

JavaScript

I would like to extrapolate, for each line, the 4 informations and plot them in a graph. using open() and fileObject.read() i can plot the txt into VSC Terminal, but i don’t know how to:

  • read the time and save it in a proper way (it’s splitted by “:”)
  • read the values, for example i could think to read the first 5 characters after “Humidity” word, the first 5 after “Temperature” and so on. For each line
  • store them in proper vector and then plot the 3 path in function of the time. I’m using numpy as library.

Advertisement

Answer

Assuming you can tolerate reading your data into a Python string, we can use re.findall here:

JavaScript

This prints:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement