- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to do multiple imports in Python?
To import multiple modules, just use the import statement multiple times. For example,
>>> import os >>> import math >>> import sys
Sometimes grouping imports make more sense. 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
- Absolute and Relative Imports in Python
- How do we return multiple values in Python?
- How do we use file.readlines() to read multiple lines using Python?
- How do you remove multiple items from a list in Python?
- Exports & Imports in JavaScript
- Dynamic imports in JavaScript.
- How can we do Python operator overloading with multiple operands?
- Using ‘{ }' in JavaScript imports?
- How to combine multiple graphs in Python
- Renaming imports and exports in JavaScript
- Awaiting on dynamic imports in JavaScript.
- How do you define multiple filters in JSP?
- How to merge multiple Python dictionaries?
- How do I loop through a JSON file with multiple keys/sub-keys in Python?
- What are static imports in java? Example.

Advertisements