-
I'm sorry if this is a dumb question, but I fairly new to python.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You were very close.
import pynmea2
class XBO(pynmea2.nmea.ProprietarySentence):
fields = (
("Blank", "_blank"),
('Temperature(outside)','temperature'),
('Pressure','pressure'),
('Humidity','humidity')
)
line = 'PXBO,23.3,992.2,56'
nmeaObj = pynmea2.parse(line)
print(f'obj: {nmeaObj}')
print(f'type: {type(nmeaObj)}')
print(f'vars: {vars(nmeaObj)}')
print(f'repr: {repr(nmeaObj)}')
print(f'temperature: {nmeaObj.temperature}')
print(f'pressure: {nmeaObj.pressure}')
print(f'humidity: {nmeaObj.humidity}') output:
|
Beta Was this translation helpful? Give feedback.
You were very close.
ProprietarySentence
XBO
, this is what matches on thePXBO
stringpynmea2.XBO
(unless you want to), just defining the class is enoughvars()
will not show the fields, since they're dynamically accessed, butrepr()
will