shanzo's instagram Feed : 2018/12/16 21:56:47

in python •  6 years ago 


#python @startwritingcode ・・・

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


Posted from Instagram via Share2Steem

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @shanzo! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You received more than 50 upvotes. Your next target is to reach 100 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations shanzo, you upvoted 500 posts via the @share2steem Curation Trails !

You reached LVL 2 and earned 0.03 SBD !
Move to LVL 3 by upvoting 1000 posts !

!tipuvote 0.03

Check the achievements list on https://share2steem.io !

Participate in our Christmas Challenge : 5 SBI shares to win !

This message is generated automatically.

This post is supported by $0.03 @tipU upvote funded by @share2steem :)
@tipU voting service guide | For investors.