Python
Python_G-009. import vs from ... import vs from... import *
X25WLK
2025. 1. 17. 11:10
Aspect | import | from ... import | from ... import * |
Usage | Imports the entire module | Imports specific functions or classes from a module |
Imports all functions, classes and variables into namespace |
Example | import math | from math import sqrt | from math import * |
Access | Requires prefixing with module name (math.sqrt) |
Direct access to imported elements (sqrt) |
Direct access without prefix (sqrt) |
Pros | - Avoids naming conflicts - Clear source of functions |
- Cleaner code - Slightly better performance |
- Simplifies code if using many functions - Less typing |
Cons | - More verbose - Slightly slower |
- Limited to specific imports - Possible naming conflicts |
- Potential for naming conflicts - Less readable |
When to Use |
Best for larger projects to maintain clarity and avoid conflicts |
When you need specific functions or classes |
Useful for quick, temporary scripts, or when conflicts are unlikely |
반응형