Forum: Mikrocontroller und Digitale Elektronik Raspberry: Python 2 funktioniert - Python 3 nicht


von Jason (Gast)


Angehängte Dateien:

Lesenswert?

Wie muss das Programm (siehe Anhang) geändert werden, so dass es unter 
Python 3 läuft?

Unter Python 2 werden Temperatur und Feuchtigkeit angezeigt:
1
23.1205371094
2
40.4630126953

Unter Python 3 kommt eine Fehlermeldung:
1
Traceback (most recent call last):
2
  File "HTU21D.py", line 100, in <module>
3
    obj = HTU21D()
4
  File "HTU21D.py", line 43, in __init__
5
    self.dev.write(CMD_SOFT_RESET)  #soft reset
6
  File "HTU21D.py", line 31, in write
7
    self.fw.write(bytes)
8
TypeError: a bytes-like object is required, not 'str'

von Jason (Gast)


Lesenswert?

Habe es gefunden. Python 3 funktioniert jetzt. Python 2 nimmt beide 
Versionen an. Python ist so witzig wie die englische Komikertruppe. 
Daher der Name.

Statt eines strings CMD_SOFT_RESET = "\xFE"

ein byte object CMD_SOFT_RESET= b"\xFE"

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.