Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only.Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Python Modules and Packages: An Introduction (Summary)
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in thediscussion section and let us know.
00:00Hey, congratulations! You completed the course.This video is going to be not only a conclusion,but a review of everything that you’ve covered throughout this course.
00:11It started with an intro and course overview,and then you dove right into writing your own module and importing it.
00:22The next video let you explore the module search path.Where will your computer look for the modules you’re importing?Theimport statement was next, and all the different forms that it can take.
00:39The next video explorednamespaces a little deeper by talking about thedir() functionand how you can use it to look up the local symbol table.
00:53After that, you got to practice executing a module as a script,and you learned about the attribute__name__.Then you learned if you import a module a second time,it doesn’t reload the contents inside of it,so you’d have to quit the interpreter and restart it,but you also saw that there is a tool in theimportlib module that you canimport calledreload(). As a project grows,it starts to make sense to look at organizing multiple modules into a package,in that sort of directory structure.
01:32Then you learned about the__init__.py file that can help you with packageinitialization.
01:41The next video was all about wildcard importing and the ways that you can set upyour module or packages to set up your user for successif a user is going to use the wildcard (*) when they’re importing.
01:55As the project may grow and the amount of modules that you have increases,it may make sense to break up the package into subpackages, and how that affectsyour namespaces. And finally, there was this conclusion and course review.
02:09I want to thank you for watching this course. Make sure that you take time topractice with what you’ve learned.
dsnyder0cnn onJan. 28, 2020
Hmmm…it looks like the last section, “Python Modules and Packages: An introduction (Summary)” has been incorrectly linked to “Python Packages”. Please update/replace the summary. Thanks.

Chris BaileyRP Team onJan. 28, 2020
Hi @dsnyderOcnn, Thanks for the head up! It has been fixed, try again or refresh.
Felix Vadan onJan. 29, 2020
Thanks for this great course Chris! Made working with modules and packages much clearer. Now I need to watch it again.
Priya katta onJan. 30, 2020
Thanks Chris! Python modules and packages concepts are much clearer now.
Ravi onJan. 30, 2020
Hi Chris, I have a question which is not related to modules, In some places when you written classes you have given Classname(), what is the difference does it make when writing as Classname() vs Classname. I know python supports both, but want to understand how python works internally with these notations

Chris BaileyRP Team onJan. 30, 2020
Hi @Ravi, This may be hard to get into deeply within a comment, but I will try to see if I can help shed some light on your question. When defining a simple new class, that isn’t based on an existing class, you would use the syntaxclass Classname: with no() after, and the methods and such would follow after the: indented underneath. When creating an object based on that class you would use the syntaxx = Classname(). That is generally what I was doing in most of these examples as my classes were really just placeholders to show the type of content you can work with in modules and packages. If you want a deeper dive I would suggest this articleObject-Oriented Programming (OOP) in Python 3 or the related video courseIntro to Object-Oriented Programming (OOP) in Python. I hope this helps.

Chris BaileyRP Team onJan. 31, 2020
Hi @Ravi, I think I may have misconstrued your question. So I will take another tack with this answer. When creating a class that is not based on / inheriting from an existing object, the() is optional and typically not used. I looked through thedocs for python 3.8 on classes and it doesn’t show that style, onlyclass Classname: . The class will still be “based” on, or in other words, always inherit from the classobject. So the syntaxclass Classname:,class Classname():, andclass Classname(object) will give the same result in Python 3. I think you may be reading code that may be trying to be more “Agnostic”, in that it could work with versions of Python 2. Here is a link to a discussion that goes deeper into it onStack Overflow.
Phil M onFeb. 1, 2020
Hi Chris,
This was a great course. It really exposed me to more of the nuts & bolts of Python. This is something I am struggling to understand, working on my Django project. I really appreciate your sharp quick and concise approach to the subject of OOP in Python Modules and Packages-even though I found it necessary to started and stopped the video many…times to practice and make sure I was on the same page - it really worked!
bphthon, very nice! This was my first time using it and I really like it. I had an issue installing it to macOS Mojave (10.14.6) but found asolution here, just incase anyone else has this issue.
Thank you - Well done!
Ravi onFeb. 3, 2020
Thanks Chris, it really helps
Sergey Morozik onFeb. 6, 2020
Great course. Brought to order and systematized all I have learned just googling things quickly. Thank you!
Pygator onFeb. 16, 2020
Really understand Package and module hierarchy now. And starting to think how i can better structure my projects with these new concepts.
mikesult onFeb. 18, 2020
Thanks Chris, excellent course. It really filled in some gaps in my python knowledge.
pshapard onApril 7, 2020
Great course Chris. I had a general understanding of packages and modules, but I gained a deeper insight into sub-packages and dot notation.
On to the next course.
Thanks,Patrick.
Adam Benson onMay 1, 2020
Thank you for presenting the concepts in a organized way. My question is about the application. Why, or really when, will I need to use this? Is there an exercise I should follow to see how this will be applicable and what happens if I don’t use these lessons (I could have missed it - wouldn’t be the first time).

Chris BaileyRP Team onMay 1, 2020
Hi @Adam Benson,Here are a couple of examples of using modules and packages.
First, if you are creating something more complex than a single script that runs by itself. When you start to have more than a couple hundred lines of code or where the functionality makes sense to divide your code up into functional parts. It’s why in Python you import frommath to have constants and other special math functions, or you import fromdatetime to do things with those type of objects in your code. Python the language itself is organized into modules and packages. It is inefficient to have all the code as one big file, when you can only import and use what you need.
Second, if you want to re-use parts of your code in later projects. Maybe you built a great function that cleans up names and addresses for your marketing emails. Not only could you now re-use that code, but someone else on your team could to. If you share those modules in a central place, you and your team could import what they need. Also, you won’t need to find a spot to copy and paste it into your one large script. You can import only what you need.
Third, if you want to share it with the world. The next level is packaging all your code up and sharing it on a packaging index. This article goes into that.How to Publish an Open-Source Python Package to PyPI, there is also a video course on this topic.
I hope I am answering your question correctly.
jeffcabral7 onMay 2, 2020
Really enjoyed this course Chris! This is a great example on how a basic/introductory course should be presented. Thanks!
Cristian Palau onMay 7, 2020
Thank you Chris for this course!
stephenwhite597 onJune 4, 2020
Nicely presented material Chris, good to see this topic layed out cleanly and systematically explained in a manner very understandable at all levels.
Should be made part of the standard teaching to get people to understand that modularisation and seperation of concerns is an important aspect of structuring a complex system that can be left behind for others to maintain and understand in the future.
Patricio Urrutia onJuly 5, 2020
Hi Chris, thanks for the course. It was very helpful!
I have a doubt, things like, for example, pandas are modules then?I had imagined that Series and DataFrames were in different modules of the “package” pandas, but it seems, due the way we import it, it is a module.
Or it is a way to accomplish this? (having all the modules and submodules inside the “pkg namespace). Maybe through theinit.py file?
Thanks!
Alain Rouleau onJuly 16, 2020
Already knew a fair amount when it came to creating and working with modules. But now I know so much more, thanks! Definitely going to use what I just learned.
Knowing how to work with packages, modules and creating your own hierarchy is kind of the missing link when it comes to Python, if you ask me. Usually that whole subject is not taught or explained very well. But you made it so simple.
Dennis Smith onDec. 7, 2020
I have referred back to the article version of this course countless times but these videos worked well to give me a deeper understanding and solidify the knowledge. Well done Chris!
Alex Duzsardi onJan. 1, 2021
Thank you for this course , it clarified a few things for me.
Krauss onMarch 2, 2021
Hey Chris, thanks for the great video course. It indeed helped me understanding and filling up some knowledge gaps. One question remains though, is there a way to get theimport command to append the newly created modulo’s path dinamically? I’ve tried using the__init__.py file to do theappend command but id doesn’t work.
qmark42 onApril 19, 2021
Thank you Chris. This course has answered several questions I have had for quite a while. Such things as what does__init__ mean and is it special, have been answered along with some dot notation questions. I will have to review the manuscript as my memory is not so great at times but now I know where to look. Again, Thank you.
nestor onApril 23, 2021
I’m preparing myself to get a Python skill to develop one Real Time measurement application using Raspberry Pi 3B, AC and DC energie sensor, this App must have connectivity options for Wi-Fi and Bluetooth and show the measurements in the GUI for mobile or a computer, so, whats Python’s tools do you recomend me to to know and review for this project if I need to do......Real Time, GUI, connectivity protocols Wi-Fi & BLE…?.......I have previus experience programming but in LabVIEW......nothing to do with Python.Thanks for your recomendation.
Carlos onAug. 1, 2022
Thanks Chris! Comprehensive tutorial. Just a comment related to bpython dundername, at least 0.20.1 on top of Python 3.8.13, Linux: running the script it isconsole instead ofmain
Tyrone onOct. 8, 2022
Thanks for this great course Chris! I learnt heaps and you made working with made working with modules and packages much clearer and now it seems so easy. Love your easy paced style, clear language and the way you lift the mist in such a matter of fact way. Well done!!.
colmedob onJan. 14, 2023
Great course, Chris. As my project grew, I needed a way to test functions independently of the main code, and this course gave me the solution.
Become a Member to join the conversation.
Course Contents

