Daily Dose of Data Science

Share this post

Import Your Python Package as a Module

www.blog.dailydoseofds.com

Import Your Python Package as a Module

Avi Chawla
Nov 13, 2022
4
Share
Share this post

Import Your Python Package as a Module

www.blog.dailydoseofds.com

A python module is a single python file (.๐—ฝ๐˜†). An organized collection of such python files is called a python package.

While developing large projects, it is a good practice to define an __๐—ถ๐—ป๐—ถ๐˜__.๐—ฝ๐˜† file inside a package.

Consider ๐˜๐—ฟ๐—ฎ๐—ถ๐—ป.๐—ฝ๐˜† has a ๐—ง๐—ฟ๐—ฎ๐—ถ๐—ป๐—ถ๐—ป๐—ด class and ๐˜๐—ฒ๐˜€๐˜.๐—ฝ๐˜† has a ๐—ง๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ด class.

Without __๐—ถ๐—ป๐—ถ๐˜__.๐—ฝ๐˜†, one has to explicitly import them from specific python files. As a result, it is redundant to write the two import statements.

With __๐—ถ๐—ป๐—ถ๐˜__.๐—ฝ๐˜†, you can group python files into a single importable module. In other words, it provides a mechanism to treat the whole package as a python module.

This saves you from writing redundant import statements and makes your code cleaner in the calling script.

Read more in this blog:ย Blog Link.

Read this post on LinkedIn: Post Link.

Thanks for reading Daily Dose of Data Science! Subscribe for free to learn something new and insightful about Python and Data Science every day. Also, get a Free Data Science PDF (250+ pages) with 200+ tips.


I like to explore, experiment and write about data science concepts and tools. You can read my articles on Medium. Also, you can connect with me on LinkedIn.

4
Share
Share this post

Import Your Python Package as a Module

www.blog.dailydoseofds.com
Previous
Next
Comments
Top
New
Community

No posts

Ready for more?

ยฉ 2023 Avi Chawla
Privacy โˆ™ Terms โˆ™ Collection notice
Start WritingGet the app
Substackย is the home for great writing