- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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)
- 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?
- How can we do Python operator overloading with multiple operands?
- How to combine multiple graphs in Python
- 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.