1
00:00:05,280 --> 00:00:09,550
let's start talking now about the Python
Standard Library now this standard

2
00:00:09,550 --> 00:00:13,930
library that ships with Python
provides a wide range of modules that we

3
00:00:13,930 --> 00:00:17,310
can use so it includes everything built
into the language that we can use

4
00:00:17,310 --> 00:00:22,180
without explicitly importing anything
plus whole lot of other useful modules

5
00:00:22,180 --> 00:00:26,180
such as shelve and random which of course
we've used in the course previously now

6
00:00:26,180 --> 00:00:31,500
I did say without explicitly importing
anything because the core built in modules

7
00:00:31,500 --> 00:00:36,040
are imported for us automatically
so I'm gonna create a new file this is the

8
00:00:36,040 --> 00:00:40,010
same project from the previous video so I'm gonna create a new Python

9
00:00:40,010 --> 00:00:46,640
file and will call this one example so when
useful command that's gonna let us see

10
00:00:46,640 --> 00:00:51,240
is dir command or dir function and thoes that uses will note that this is not

11
00:00:51,240 --> 00:00:55,580
related to the dir command you can use
from a command prompt to print out a

12
00:00:55,580 --> 00:00:59,190
list of directories so to see what is
imported for us automatically we can

13
00:00:59,190 --> 00:01:05,030
print the output from dir so we could do
something like....

14
00:01:05,030 --> 00:01:11,520
to call the dir method run that and right

15
00:01:11,520 --> 00:01:17,020
click Tim and click run example I remember this time
and you can see when I've done that

16
00:01:17,020 --> 00:01:20,990
we got a whole heap of information

17
00:01:20,990 --> 00:01:24,160
as you can see there, now we're gonna be
covering this in a lot more detail later

18
00:01:24,160 --> 00:01:27,770
but it's worth noting that anything
whose name starts with an underscore

19
00:01:27,770 --> 00:01:32,140
here is something that we shouldn't be
changing without good reason so if the

20
00:01:32,140 --> 00:01:35,810
name starts with two underscores like
these two and then not intend to be

21
00:01:35,810 --> 00:01:40,450
changed at all so in fact
there's no such thing as private

22
00:01:40,450 --> 00:01:44,600
variables in Python and everything is
available everywhere but the convention

23
00:01:44,600 --> 00:01:49,350
is to use underscores to intention so starting a name

24
00:01:49,350 --> 00:01:54,020
with an underscore indicates that it's
private to its module but it's up to you

25
00:01:54,020 --> 00:01:57,910
as the programmer to inspect that convention
because Python itself doesn't prevent you

26
00:01:57,910 --> 00:02:00,630
from changing and that's done by design

27
00:02:00,630 --> 00:02:05,950
but getting back to the dir as you can see on the screen
here now we are not going to look at most of the entries as they are

28
00:02:05,950 --> 00:02:09,160
to do with the internal running
of Python but a good one here is this

29
00:02:09,160 --> 00:02:13,770
first one underscore underscore builtins
underscore underscore this is the module containing

30
00:02:13,770 --> 00:02:18,320
the Python built-in identifiers and there is
actually a list that I'm going to put on the

31
00:02:18,320 --> 00:02:22,360
screen and I'll share this link in the
Resources section and will just open a

32
00:02:22,360 --> 00:02:30,110
browser and go that URL now that's a decent list of all
the built-in functions from or based on

33
00:02:30,110 --> 00:02:34,500
that module the built-in
modules but with that said that's one way of

34
00:02:34,500 --> 00:02:39,220
doing it but we can
also use the command to find out a bit more as well

35
00:02:39,220 --> 00:02:48,390
so come here on the next line ill put..

36
00:02:48,390 --> 00:03:01,070
...and if we run that that gives us a whole heap of

37
00:03:01,070 --> 00:03:05,610
stuff and obviously you want to scroll that
but this is Python so we can easily

38
00:03:05,610 --> 00:03:09,270
display that of course in a more readable
format as we've done this before so

39
00:03:09,270 --> 00:03:13,090
let's just comment that line out and use our

40
00:03:13,090 --> 00:03:32,820
handy for so.....so run again and I need a colon there so run again and now we got a decent list here so we got

41
00:03:32,820 --> 00:03:39,920
a whole heap of errors at the top but also just scrolling
down the list you will see there is the false one

42
00:03:39,920 --> 00:03:48,300
there is none we seen that before and true down here as well that just 3 and....

43
00:03:48,300 --> 00:03:55,990
if you go a bit further you can see the dir hex input

44
00:03:55,990 --> 00:03:56,820
and bin up here

45
00:03:56,820 --> 00:04:01,820
slice and so on so essentially you should be able to
recognize quite a few of these other

46
00:04:01,820 --> 00:04:05,160
entries and even things like list is
there on the screen

47
00:04:05,160 --> 00:04:11,020
map open print etc of course that's more
interesting than actually useful but if

48
00:04:11,020 --> 00:04:14,820
we import shelve we can have a look at
what that provide so lets close this down

49
00:04:14,820 --> 00:04:22,050
so just delete the codes here and start again so
what we can do is import shelve and

50
00:04:22,050 --> 00:04:34,500
have a look at what it actually provides so...

51
00:04:34,500 --> 00:04:44,320
....and run that and you can see
we got a whole heap of bits and pieces there

52
00:04:44,320 --> 00:04:49,690
relating to shelve and the first list
shows you shelve on the list because we imported

53
00:04:49,690 --> 00:04:55,200
it that's now coming up in our list when
we print dir and printing dir on the shelve as you see on the

54
00:04:55,200 --> 00:05:00,450
third line there has shown the objects and
methods available from the shelve module

55
00:05:00,450 --> 00:05:04,430
of course we've used the open function
before to open a shelve and this returns

56
00:05:04,430 --> 00:05:08,450
a shelve object so you may notice that
close doesn't appear in the list and I'll just run it again

57
00:05:08,450 --> 00:05:19,270
so looking at the list when we use open there is the
open method in the end and when we do

58
00:05:19,270 --> 00:05:23,870
that it returns a shelve object one of these
but you will notice that close doesn't

59
00:05:23,870 --> 00:05:27,090
appear in the list and that's because
it's a method of the shelve

60
00:05:27,090 --> 00:05:31,140
class we're not interested in the
underscore method so we can filter out to see what

61
00:05:31,140 --> 00:05:39,910
a shelve object provides just to show you how that works so we can do something like, will leave the shelve import there and will put...

62
00:05:45,780 --> 00:06:04,150
and I will put a test here to ignore underscore so..so let us run that and you can see now

63
00:06:04,150 --> 00:06:08,630
that apart from pop and popitem we've
seen all these other methods either when

64
00:06:08,630 --> 00:06:12,320
looking at shelve or when discussing
dictionaries and in face Intellij provides

65
00:06:12,320 --> 00:06:16,470
a similar list plus a lot more in order
of completion we type the full stuff after shelve

66
00:06:16,470 --> 00:06:27,840
so if we type something here going back
to the code so if we type....you can see there is

67
00:06:27,840 --> 00:06:31,190
a big list of things that IntelliJ
will bring up automatically

68
00:06:31,190 --> 00:06:34,880
IntelliJ is quite smart that way that it
can present all this information to us as well

69
00:06:34,880 --> 00:06:39,220
now some of the standard modules are
written in C these are generally the

70
00:06:39,220 --> 00:06:43,340
ones that provide access to system
functionality such as File I/O but many of

71
00:06:43,340 --> 00:06:46,200
them are actually written in Python
and we can examine the source code from

72
00:06:46,200 --> 00:06:50,130
IntelliJ holding down the Ctrl
key and clicking on the module name shelve

73
00:06:50,130 --> 00:06:54,900
in this case so we can come over here
and we can I believe its control

74
00:06:54,900 --> 00:06:59,700
on a PC but on a MAC it is command click on
a command hold command down and click on

75
00:06:59,700 --> 00:07:05,230
shelve that's gonna give us access to the
source code for the shelve.py and

76
00:07:05,230 --> 00:07:10,290
you can just scrolling down there is some actual code
that is part and parcel of Python

77
00:07:10,290 --> 00:07:13,640
so until we have covered functions and classes the code you can see on the screen

78
00:07:13,640 --> 00:07:16,530
probably looks a bit horrible to you so we are gonna leave it there and have a look at some of the

79
00:07:16,530 --> 00:07:20,890
standards library code later in the course
so on the next few videos we are gonna look at

80
00:07:20,890 --> 00:07:24,470
some of the modules that come with Python but
will finish this video by saying how the

81
00:07:24,470 --> 00:07:28,850
help function can be useful to work out how to use some of the

82
00:07:28,850 --> 00:07:30,280
various modules

83
00:07:30,280 --> 00:07:36,850
so let us just close this file off we only got shelve imported so what I'm gonna do is delete that and on

84
00:07:36,850 --> 00:07:42,900
line 3 I'm gonna type....

85
00:07:42,900 --> 00:07:47,000
if I run that you can see that actually
gives us quite a bit of information

86
00:07:47,000 --> 00:07:52,500
about , quite a detailed amount of
information about shelve how to use it

87
00:07:52,500 --> 00:07:57,510
description of what it is the various
parameters interfaces and so on and also a link to the

88
00:07:57,510 --> 00:07:58,500
documentation

89
00:07:58,500 --> 00:08:02,230
so you can see here there is a link we can get and from
their we can click on that goes straight

90
00:08:02,230 --> 00:08:14,630
to documentation in a browser so copy that
go back to the browser and press enter

91
00:08:14,630 --> 00:08:17,370
generally following the link is better
because you get the object or output rather

92
00:08:17,370 --> 00:08:22,530
you got this way of looking at the data or coming
back to a browser and seeing it in that format

93
00:08:22,530 --> 00:08:26,910
to me I would prefer to use this format the
browser I think it's a lot easier to

94
00:08:26,910 --> 00:08:31,180
read but it's personal preference and
you got the ability to choose either way

95
00:08:31,180 --> 00:08:34,440
when you actually choosing a
documentation and we do suggest that you

96
00:08:34,440 --> 00:08:38,120
do take some time in read this
documentation you don't need to know

97
00:08:38,120 --> 00:08:42,559
or understand it word for word but it can
be a good way to help solidify your

98
00:08:42,559 --> 00:08:46,200
understanding of how some of the
internals work within Python it is really really

99
00:08:46,200 --> 00:08:51,680
handy and you can also request help on
individual functions so for

100
00:08:51,680 --> 00:08:58,510
example we could change that to import
random and here we could type...

101
00:08:58,510 --> 00:09:03,730
.....and we can get some help just on that again it is quite
short but it does give you the

102
00:09:03,730 --> 00:09:07,810
information relating to the parameters and so forth for that particular function

103
00:09:07,810 --> 00:09:11,250
so I'm gonna end this video here in the next one
we're going to continue our discussions

104
00:09:11,250 --> 00:09:12,930
of modules and imports

