Ankündigung
Einklappen
Keine Ankündigung bisher.
- √ - Einbinden des Python math Modules
Einklappen
X
-
Hi Peter,
ja, das Problem liegt am Namespace. Siehe Google.
Mach das Import einfach in die Funktion, dann sollte es auch funktionieren.
Bis bald
Marcus
Einen Kommentar schreiben:
-
Alternative 1:
Alternative 2:Code:#!/usr/bin/env python3 # from math import sqrt # ... def calc_position_percent(): position_umdrehung = (float(rollo.conf['laufzeit_ab']) - position_neu) * ([COLOR="Red"]sqrt[/COLOR]((2 * int(rollo.conf['laenge']) + 17) / 7.5) - 1.5) / float(rollo.conf['laufzeit_ab']) position_neu_cm = int(rollo.conf['laenge']) - (3.75 * position_umdrehung * (position_umdrehung + 3)) position_neu_prozent = int(100 * position_neu_cm / int(rollo.conf['laenge']))
Bei Alternative 1 kommt die Fehlermeldung, dass sqrt nicht definiert ist, bei Alternative 2 dasselbe für math.Code:#!/usr/bin/env python3 # import math # ... def calc_position_percent(): position_umdrehung = (float(rollo.conf['laufzeit_ab']) - position_neu) * ([COLOR="red"]math.sqrt[/COLOR]((2 * int(rollo.conf['laenge']) + 17) / 7.5) - 1.5) / float(rollo.conf['laufzeit_ab']) position_neu_cm = int(rollo.conf['laenge']) - (3.75 * position_umdrehung * (position_umdrehung + 3)) position_neu_prozent = int(100 * position_neu_cm / int(rollo.conf['laenge']))
Any ideas?
Gruß
Peter
Einen Kommentar schreiben:
-
Hallo,
zeig doch mal den Code.
Bis bald
Marcus
Gesendet von unterwegs
Einen Kommentar schreiben:
-
- √ - Einbinden des Python math Modules
Hallo,
ich möchte für eine Berechnung das math-Modul in Python einbinden, um die sqrt-Funktion zu nutzen. Aber weder
nochCode:import math
führen zum Ziel.Code:from math import sqrt
Entweder bekomme ich bei ...math.sqrt... die Meldung, dass math nicht definiert ist oder bei sqrt(...) die Meldung, dass sqrt nicht definiert ist.
Muss die import-Anweisung an eine bestimmte Stelle in der Python-Datei oder muss ich die Bibliothek vorher irgendwo hinladen?
Ich bin ratlos, leider zeigt das Log auch keine weiteren Fehler oder Hinweise an.
Danke & Gruß
PeterStichworte: -


Einen Kommentar schreiben: