0Pricing
Mojo Academy · Lektion

Ein Python-Modul importieren

Verwenden Sie Python.import_module in Mojo.

Ein Python-Modul importieren ist eine kostenlose Mojo Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Mojo Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.

Keep Your Favorites

Mojo lets you reach into Python's huge ecosystem, so you keep using the libraries you already love while gaining speed. 🐍

The Python Object

Interop starts with the built-in Python object, your gateway to importing and calling Python from inside Mojo code.

from python import Python

import_module

To load a Python module, call Python.import_module with the module name as a string. It hands you the module back.

var np = Python.import_module("numpy")

Name It Like Python

The string you pass is exactly the name you would write in a Python import, like "math" or "numpy". Same names, same modules.

var math = Python.import_module("math")

Store the Handle

Save the returned module in a var so you can use it many times. That variable is your handle to everything the module offers.

var os = Python.import_module("os")

It Can Fail

If a module is missing, the import can raise an error. So importing usually lives in a function marked with raises.

fn load() raises:
    var np = Python.import_module("numpy")

Reach the Contents

Once imported, use dot access to reach functions and values inside the module, just like in Python itself.

var pi = math.pi

Use Installed Packages

You can import any third-party package that is installed in your Python environment, not only the standard library.

var pd = Python.import_module("pandas")

One Bridge, Many Modules

Import as many modules as you need. Each call returns its own handle, letting you mix several Python libraries in one Mojo file.

Environment Matters

Mojo uses your active Python environment to find modules. If a package imports in Python, it will import in Mojo too.

Why It Matters

Importing Python means you never start from zero: decades of tested tooling are one line away inside your fast Mojo code. ⚡

Quick Check

Recall how you bring a Python module into Mojo.

Recap

You learned to import Python with Python.import_module, store the handle, and unlock any installed library from Mojo. 🎯

Häufig gestellte Fragen

Ist die Lektion „Ein Python-Modul importieren“ kostenlos?

Ja — der vollständige Text von „Ein Python-Modul importieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Mojo Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Mojo Academy-Kurs umfasst insgesamt 4 Lektionen.

Was lerne ich in „Ein Python-Modul importieren“?

Verwenden Sie Python.import_module in Mojo. Du übst Mojo Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.

Brauche ich Erfahrung, um Mojo Academy zu starten?

Keine Vorkenntnisse erforderlich. Mojo Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.

Wie lange dauert die Lektion „Ein Python-Modul importieren“?

Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.

Kann ich in dieser Mojo Academy-Lektion Code schreiben und ausführen?

Ja. Jede Mojo Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.

Alle Lektionen in diesem Kurs

  1. Ein Python-Modul importieren
  2. Python-Funktionen aufrufen
  3. Daten über die Brücke übertragen
  4. Wann Sie Python-Interop verwenden
← Zurück zu Mojo Academy