filmov
tv
Python Tutorial: Introduction to packages & documentation

Показать описание
---
You've now learned some important software engineering concepts. We're now going to look at how beneficial these concepts can be as a user of python open source software.
Namely, we're going to investigate packages. We'll cover how to install packages from the 'Python Package Index', and we'll see how these packages leverage software engineering concepts we've covered.
Later in the course, we'll talk more about the 'Python Package Index', or PyPi for short, but for now, all you need to know is that PyPi gives us an easy platform to leverage published packages.
Thanks to packages being modular, we can easily install them from PyPi using a tool called pip.
pip is actually a recursive acronym that stands for 'Pip Installs Packages', and it does just that.
The practice of leveraging pip install can save a lot of time and lets us avoid reworking problems that have already been solved and packaged by some smart members of the python community.
If we wanted to install the popular package numpy we conveniently use the command pip install numpy. Barring any unexpected issues we now have numpy installed and we can leverage all the benefits that come with this powerful package.
Note that pip will also install a package's dependencies as long as they're on PyPi. However, in some cases, a package's dependencies might require a little extra work.
So how do we leverage numpy's features? Again thanks to good software engineering, numpy has excellent documentation available both on the web and in the package itself. Here we'll focus on the documentation shipped with the package.
Let's say we want to count the number of work days in the year 2020. numpy provides the function, busday_count, that can help us accomplish this, but how do we use it? To view a function's documentation we can use the function, help.
Here is the syntax we can use to learn more about numpy's busday_count method.
And here's the response to our call for help. Note that the output has been truncated.
From this documentation, we see a description of the function, its parameters, and what we can expect as output. Additionally, we see an example that perfectly matches our described use case.
We just saw that we can use help to see a method's documentation, but we can also call help on any object in python.
We can call help on the numpy package to see some high-level documentation on what functionality it provides.
And here we call help on a number. From the output, we can read up on python's integer class.
As you can probably tell, having this documentation can be invaluable to users like you and me. But sometimes you might call help on an object and see that there isn't any documentation. It's up to the developer to include these helpful tidbits.
Including documentation for your packages, classes, and methods will make using your code much easier. It's important to remember that future-you is also a user who will benefit from this documentation.
Believe me, documenting your code, even if you're the only user, can save a lot of wasted time and headaches. I've personally suffered through relearning how to use code that I wrote, but this is totally preventable with good documentation.
Ok, we covered how to pip install packages and how to read documentation using help. In the following exercises you'll get to practice both of these invaluable skills. Good luck!
#PythonTutorial #DataCamp #Software #Engineering #DataScientists #Python