python __import__
时间: 2023-09-04 07:14:30 浏览: 62
`__import__` is a built-in function in Python that allows you to import a module dynamically at runtime. It is a low-level function and is usually not recommended to be used directly, as there are more convenient ways to import modules in Python.
Instead of using `__import__`, it is generally recommended to use the `import` statement to import modules. For example, if you want to import the `math` module, you can simply use `import math`.
Here's an example of how you can use `__import__` function:
```python
module_name = "math"
module = __import__(module_name)
```
This will import the `math` module and assign it to the variable `module`. However, it is worth noting that using `__import__` directly is uncommon in most scenarios, and the `import` statement is usually preferred for readability and maintainability.