Physically, a package is a folder of modules, and it may contain more folders that have more folders and modules.Ĭonceptually, a Python package is a namespace, meaning the modules in a package are bound by the package’s name and may be referenced by that name. Python packages typically comprise several modules. The term “module” is not strictly defined in Python it serves as an umbrella term for reusable code. In contrast, a module is a Python program that programmers can import into other programs or directly in the interactive mode of the Python shell. Running the script is as simple as using the Python command in the terminal. Programmers can write a script in a text editor of their choice and save it in the. A script comprises code you run in a shell to accomplish a specific task. What is a Package in Python?īefore you can understand what a Python package is, you must have an idea of what scripts and modules are. This article will show you how to create a Python package. When the number of modules (simply stated, a module might be just a file containing some classes) in any project grows significantly, it is wiser to organize them into packages – that is, placing functionally similar modules/classes in the same directory. When you've got a large number of Python classes (or "modules"), you'll want to organize them into packages. Picture a scenario where you have to write a parser every time you want to use one – it would waste a lot of time and effort, and programmers wouldn’t get anything else done. If packages didn’t exist, programmers would need to spend a lot of time rewriting code that’s been written before. Using packages is an essential part of Python programming.
0 Comments
Leave a Reply. |