
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How to use multiple modules with Python import Statement?
To import multiple modules with a single import statement, just separate the module names by commas. For example,
>>> import math, sys, os
If you want to change the name under which the modules are imported, just add as after each module name followed by module alias. For example,
>>> import math as Mathematics, sys as system
If you have a list of modules you want to import as strings, then you can use the inbuilt __import__(module_name). For example,
>>> modnames = ["os", "sys", "math"] >>> for lib in modnames: ... globals()[lib] = __import__(lib)
- Related Articles
- How to install and import Python modules at runtime?
- How we can import Python modules in Jython?
- How we can import Python modules without installing?
- What is the use of import statement in Python?
- Python import modules from Zip archives (zipimport)
- How to use remote python modules?
- What is the use of "from...import" Statement in Python?
- What is the use of "from...import *" Statement in Python?
- How can I import modules for a Python Azure Function?
- How to use multiple conditions in one if statement in Python?
- How we can bundle multiple python modules?
- How to import Python modules by default at the time of program starts?
- How to use Python modules over Paramiko (SSH)?
- How to use else statement with Loops in Python?
- Can we iteratively import python modules inside a for loop?

Advertisements