Python Start To Learn Python Right Now EP15: Full Guide to Use Modules in Python

In this post, I'm going to explain Python modules and how to access them with some module tips. Python modules are the best thing I like in Python. Because Python has a massive range of modules in every category like hacking, GUI designing, Server-side developing, Ai developing, Machine learning, and more advanced fields. Actually, these modules are the life of Python programming. 


Get started with Python modules 

   As I mentioned above Python has lots of modules. We are talking about them in series by series. We are using the PIP command in command prompt(cmd) to use install any kind of Python package.  Also, you can download a '.whl' file of a package and install it using cmd. 

  Install a package using PIP

    pip install my_package_name


Add packages to your projects

   we are using import calling to add packages to your project. 

   import my_module_name


when you use a function or command in a package you have to do it using the package name. 

example : my_module_name.myModule

    Here I call the module function using its package name. but what if the package has a long name. Do we have to write all? no. because we have a solution for that. We can use as a calling to reduce that error. 

example: import my_module_name as mmn

               mmn.myModule

  In there I change the name of the imported module name temporarily to my project. So, we can call that module using the 'mmn' syntax in this Python file. 

  In the above, we learn how to avoid the long name issue in Python Modules. But How I say there is a way to import a module without any name. I mean you can call the module functions directly without any name. We are using from and * keyword to it.

 example: from my_module_name import

               myModule

    In this way, it is importing whole the module functions instead of the module package. Simply is adding files in the module instead of the adding module main folder. 

   But there is also a negative mark with importing them all without any module name. because you can miss understanding your program codes after writing the program. because there is no mark to identify which code you get from the specific library. 

Adding specific functions from a Module

    When you need just a special function in a package, you can do it when importing the code

example: from my_module_name.myModule import softexs

   Here I'm using from and import to do that. Simply my_module_name is the package and myModule is a function in that. So we got a special variable of command in that function called softexs. 


  This is all for this post. I hope you'll understand all because this is a bit easy episode. But feel free to comment below if you have any questions. 


Post a Comment

If you have any doubt, Let us know

Previous Post Next Post