Welcome to a brand new section.
And here we're going to be talking about libraries and modules.
So what exactly are these?
Let's print this scenario, right? What if we wanted to write a program
that will hash plain text, right? So say, for example, we wanted to store our
passwords in a file. Obviously, we'd want to hash them.
We don't want to stop passwords in a plain text. So how would we write a program
that will hash these passwords?
There are two options. OK?
We could either decide to write the program from scratch,
which might take a lot of time or
very simply,
we can use something called a module
that already has the code
that we would need to hash our text. So
a module is typically a Python file
that already contains code.
It could be functions, variables, classes, statements, you name it
that serves a specific purpose
while a library as you might now have imagined
is often a package group of these modules organized around a broader goal.
So you can think of modules as very
specific functions that serve a very specific purpose.
While a library would be a collection of such modules
as an example,
we do have the datetime pi
this is a module
that has functions specifically for working with dates and times.
We also have a library called the Hashlib,
the hash library which would be
the library we would have to use in order to hash our plain text.
Now, what do we have in the hash library?
We have different types of algorithms.
We have the MD5 that will create a 128 bit hash.
We have the sha one that will generate a 160
bit hash sha 256 which will generate the 256.
And of course, the sha 512 which will then generate a 512 bit hash.
There are also other types of functions within this library like the hashlib dot new
that will accept two parameters name data
which we can then use to create a hash with a specific algorithm name.
So
moving forward
libraries
can either be built in, we call them standard libraries.
This will come default with your Python installation or
we can also use libraries that are external. We refer to them as third party.
These libraries don't come
with your Python installation. So you'll have to install them manually yourself
and they're developed by the Python community.
So one more time modules have very specific code that sells very specific function
while libraries will be a collection of these modules.
One other thing I want you to
realize is that within the Python community,
you may also hear of another term called packages.
Packages are somewhere in between modules and libraries
and that they are also a collection of modules.
But the modules tend to be very closely related in purpose.
They're not quite as broad
as library. So for example, you can have your email package
and in the email package, you'll have modules like your email message,
your email dot
MIME, your email
TS and so much more.
Another advantage of packages is that they can allow us to
organize these modules in a hierarchical structure by using folders and
sub folders.
So each package typically will contain the
init dot py file
which tells Python that hey,
this particular directory, it's not a library, it's actually a package.
This is how we can help Python differentiate between
the package and the library.
The the package will have a file specific specifically called
the
init dot
py file. So that's it for libraries, modules and packages German
Linux
video where
we will not begin to work with them.