Python __import__

While writing a code, tright here could be a need for some certain modules. So we import those modules by using a single line code in Python.But what if the name of the module essential is well-known to us only in the time of runtime? How can we import that module? One deserve to use the Python’s inbuilt __import__() function. It helps to import modules in runtime additionally.Syntax: __import__(name, globals, locals, fromlist, level)Parameters:name : Name of the module to be importedglobals and also locals : Interpret namesformlist : Objects or submodules to be imported (as a list)level : Specifies whether to usage absolute or relative imports. Default is -1(absolute and also relative).Example #1 :


You watching: Python __import__

Application :__import__() is not really crucial in daily Python programming. Its straight use is rare. But periodically, when tright here is a need of importing modules in the time of the runtime, this feature comes quite handy.Attention geek! Strengthen your structures via the Python Programming Foundation Course and also learn the basics. To start with, your intercheck out preparations Enhance your Data Structures concepts with the Python DS Course. And to start through your Machine Learning Journey, sign up with the Machine Learning – Basic Level Course


https://media.sibbap.org/auth/avatar.png
Competitive Programming Live Classes for Students
DSA Self Paced Course

See more: 11" Paw Print Latex Balloons

DSA Live Classes for Working Professionals
Python map() functionTaking input in PythonAdding brand-new column to existing DataFrame in PandasPython DictionaryRead JSON file using Python
How to acquire column names in Pandas dataframePython program to transform a list to stringRead a file line by line in PythonIterate over a list in PythonPython String | replace()
We usage cookies to ensure you have actually the finest looking endure on our website. By utilizing our site, youacunderstanding that you have actually read and also interpreted ourCookie Policy & Privacy PolicyGot It !