Ankündigung

Einklappen
Keine Ankündigung bisher.

- √ - Einbinden des Python math Modules

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    - √ - 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
    Code:
    import math
    noch
    Code:
    from math import sqrt
    führen zum Ziel.

    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ß
    Peter

    #2
    Hallo,

    zeig doch mal den Code.

    Bis bald

    Marcus


    Gesendet von unterwegs

    Kommentar


      #3
      Alternative 1:
      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']))
      Alternative 2:
      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']))
      Bei Alternative 1 kommt die Fehlermeldung, dass sqrt nicht definiert ist, bei Alternative 2 dasselbe für math.

      Any ideas?

      Gruß
      Peter

      Kommentar


        #4
        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

        Kommentar


          #5
          Thanx. Hat funktioniert :-)

          Kommentar

          Lädt...
          X