
Let’s learn the Python programming language together!
.
.
Step 7, and consequently the final step in my beginners guide, is all about organization. And when it comes to organization in Python, we are talking about Modules and Packages.
.
.
Modules and Packages are really just fancy names for files and directories within your Python application.
.
.
A module is any file in your application that has a .py extension. The Module name is name of the file and the file can contain any combination of functions, classes, variables, etc.
.
.
The ideal strategy when it comes to Modules is to group all like functionality into a single Module. For example, if you are building a tic-tac-toe game, maybe one module has functionality around the board, another for a player, another for symbols (ax’s and Os). This helps to logically break your app into pieces.
.
.
Packages on the other hand are directories within your application. Packages help to create namespaces within your application to help further structure your application. Now you can group Modules into sections to help make sense of importing code throughout your app.
.
.
In the tic-tac-toe example, maybe you have a “logic” package and a “ui” package and break things up that way.
.
.
Finally, in order for a directory to be a Package, you need to have a special file in that directory, named “init.py”. This file can be empty, but it must be there for the directory to be a Package!
.
.
Now take a look at your app and start to break things up to add some must needed structure!
.
.
#share2steem #programming #programminglanguage #pythonlanguage #pythoncode #pythonprogramming #learncode #learntocode #learnpython #technology #codelife #pythonprogramminglanguage #development #webdevelopment #buildtheweb #startwritingcode #pythonmodule #pythonpackage #python2 #python3 #python2018


shaneelsomduth
