WEBVTT

0
00:00.140 --> 00:06.650
Now, I've mentioned a lot about using code that other developers have written, and the most common

1
00:06.650 --> 00:10.280
way to do this is through using packages of code.

2
00:10.400 --> 00:16.250
In this lesson, I'll show you how to integrate an existing package of code into our project so that

3
00:16.250 --> 00:21.110
we can practice creating objects and working with attributes and methods.

4
00:21.200 --> 00:29.030
Now we've seen modules of code where each file that we create in our project is essentially a module

5
00:29.030 --> 00:30.100
in itself,

6
00:30.250 --> 00:37.810
but a package differs from a module in the sense that it's actually a whole bunch of code that other

7
00:37.810 --> 00:45.490
people have written. Lots and lots of files, all packaged together to achieve some sort of goal or purpose.

8
00:45.850 --> 00:53.830
Now, let's say that we want to create a table of Pokemon and their type, so we wanted some way of

9
00:53.830 --> 01:00.430
documenting that Pikachu is an Electric type, and maybe Squirtle is a Water type.

10
01:01.450 --> 01:07.450
Now, if we wanted to do that in ASCII so that we could print it in the console, well, then we would

11
01:07.450 --> 01:10.540
have to go about formatting it, and it'll be quite painful.

12
01:10.540 --> 01:14.440
So we might have to print some sort of pipe,

13
01:14.440 --> 01:18.180
and then maybe we would have the name of the field,

14
01:18.180 --> 01:26.040
so Pokemon name, and then maybe another pipe, and then we would have the name of the next column, which

15
01:26.040 --> 01:27.180
is their type.

16
01:27.390 --> 01:35.070
And then finally we would close that off, and then we would have to print some sort of horizontal

17
01:35.070 --> 01:40.890
line maybe like this, and so on and so forth, just to create this table.

18
01:40.890 --> 01:46.640
And it's quite difficult if you're not used to manipulating ASCII and visualizing it.

19
01:46.640 --> 01:49.280
I certainly am not up to this task.

20
01:49.490 --> 01:51.800
So what could we do instead?

21
01:51.830 --> 01:59.540
Well, we could search for a Package that other developers have created to achieve this goal, and the

22
01:59.540 --> 02:06.170
place that we would do that is somewhere called PyPI, which is the Python Package Index.

23
02:06.170 --> 02:13.040
And this is a bunch of software for the Python programming language that is developed and shared by

24
02:13.040 --> 02:14.210
the Python community.

25
02:14.210 --> 02:20.300
So we can see their source code, but more importantly, we can see how to implement the code and how

26
02:20.300 --> 02:22.490
to put it into our project.

27
02:23.030 --> 02:26.780
In here, I'm going to search for something called, prettytable.

28
02:27.440 --> 02:36.250
And this is a very simple library that is going to help us to display tables in an ASCII format.

29
02:36.460 --> 02:41.380
We can click on the project links to find out more about it,

30
02:41.380 --> 02:47.650
and this will take us to the Google Code Archive where the documentation is hosted.

31
02:47.680 --> 02:53.890
If you go to Wikis and go to tutorial, you'll see some documentation on how to use it.

32
02:53.910 --> 03:01.740
Now, this particular package is not as extensive as the Turtle graphics package, so there's actually

33
03:01.740 --> 03:06.960
not a lot of things you can do with it, but it's got more than we need for our use case.

34
03:07.590 --> 03:12.780
The first thing we have to do is to install this package into our project.

35
03:12.810 --> 03:19.280
Now, unlike the Turtle package, which is already pre-loaded with every copy of Python, in order to

36
03:19.280 --> 03:25.640
use the packages that you find in the Python Package Index, you actually have to install it.

37
03:25.640 --> 03:27.890
So here's how we do it in PyCharm.

38
03:27.890 --> 03:30.530
First go to the Preferences,

39
03:30.530 --> 03:32.930
so in windows I think it's under File,

40
03:32.930 --> 03:37.220
and then Preferences. On Mac, it's under PyCharm and then Preferences.

41
03:37.220 --> 03:43.190
And then here you'll see a whole bunch of things you can change including the Editor or Appearance,

42
03:43.190 --> 03:45.080
which we've already messed around with.

43
03:45.080 --> 03:47.750
But I want you to click on your project.

44
03:47.750 --> 03:50.870
So my project is called day-16-start.

45
03:50.870 --> 03:53.720
And then we're going to go into the project interpreter.

46
03:53.720 --> 04:02.330
And here we can click on the plus button to install any package that you find in the Python Package

47
04:02.330 --> 04:03.050
Index.

48
04:03.080 --> 04:04.910
Make a note of what it's called,

49
04:04.910 --> 04:07.150
so ours is called PrettyTable.

50
04:07.150 --> 04:10.870
And then we're going to search for it inside the available packages,

51
04:10.870 --> 04:14.740
and once we found it we're going to select it, and then click install.

52
04:16.300 --> 04:22.150
So now it's installed successfully, we can go ahead and close this down, and click Okay.

53
04:22.150 --> 04:27.010
And we can now access this package called PrettyTable in our code.

54
04:27.160 --> 04:32.550
Again I'm going to import it so I can say, import prettytable.

55
04:32.550 --> 04:36.690
And now I can use everything that's inside this package.

56
04:36.720 --> 04:43.800
Now if you want to see the source code you can actually right-click on it and select go to implementation.

57
04:43.800 --> 04:49.110
And this will take you to the Python file where this entire Pretty Table is implemented.

58
04:49.110 --> 04:53.520
So all of the code that they've written. It's a little bit daunting,

59
04:53.520 --> 04:59.130
and it's got a lot of code in it, but we don't have to worry about how the code is created and how

60
04:59.130 --> 04:59.970
it works.

61
04:59.970 --> 05:06.810
All we need to do is look at the documentation for this package and see how we can implement it into

62
05:06.810 --> 05:07.800
our project.

63
05:07.800 --> 05:13.740
Now, in the next lesson, we're going to get some practice constructing a PrettyTable object and, using

64
05:13.740 --> 05:17.610
the documentation to explore this object's attributes and methods.

65
05:17.610 --> 05:19.050
For all of that and more,

66
05:19.050 --> 05:19.860
I'll see you there.