📺 Develpreneur YouTube Episode

Video + transcript

Python Certification Training - Platform and System.Dir

2021-07-13 •Youtube

Detailed Notes

We cover the Platform and System functions you are likely to see on the certification exam in this episode.

Helpful links: https://docs.python.org/3/library/platform.html

Learn more about the overall certification and syllabus here: https://pythoninstitute.org/certification/pcap-certification-associate/pcap-exam-syllabus/

Github repository for code examples: https://github.com/robbroadhead/PythonCertificationSeries

Transcript Text
[Music]
hello and welcome back
we're continuing our season our series
actually we're looking at
the python certification and working our
way through
numerous things that we're going to see
on that exam this episode we're going to
continue looking at some specific
commands
and we're going to focus on the platform
module this time around now there's a
link
that i will put in the show notes that
has got what we're looking at plus
more than a few others that are out
there but we're gonna look at a couple
of key
uh commands that are out there to start
this one off so let's start with
uh platform platform uh now this one's
got two
uh you can give it zero parameters or
there's
two others flags that you can provide
so if i do that
let's do this let's clear that first
and we'll blow it up a little bit more
so with platform uh
here we go now the first one i did if i
just do platform itself and this is
because this is what i'm on and what i'm
on is it tells me this is mac os 10
dot 16 it's a x8664 machine
i3864 bit now the second one i did
and uh let me go get what those actual
names of those are is it's whether it's
aliased or terse
alias doesn't work in all
uh systems essentially so that's why
we're going to find in both of these
oh let's go flip back over here when
whether we set alias to zero one
we still get the same thing we're gonna
get this guy but now the other part is
terse which is short
so the short version if we look at the
platform is going to be
our operating system if we add the long
version then it's going to add
you know what kind of a processor this
is basically this is an i386 it's an
intel chip it's a 64-bit
system so it's some additional
information we can get
oh you may use this occasionally i have
seen this where people are using it to
do maybe
maybe you've got like some scripts that
are operating system specific
or require a specific version of an
operating system so
you can take a look at that to make sure
you know what your platform is
you may just use it for logging just to
get an idea of what
people are using now the next one is
machine
so if you look at machine it also has
no parameters and machine
is funny enough going to give you in
this case
part of what is in the verbose version
of the
uh the platform and so this is actually
your machine right here
so you can either do the whole thing or
you can actually pull that out
specifically we're going to see
something
similar with
processor processor
so we see here with our processor
processor
it's going to be i386 and you see that's
there so this
actually this platform happens to be
the essentially the operating system
the machine the processor processor
and then you're going to find out
very similarly oh
let me paste that properly
and then we do system
you can see that uh system is going to
give you the operating system name so
i'm sorry that's not saying that's the
last bit but it's not
so system this is essentially the
operating system name
so it may be and i forget what you'll
get on some other stuff i think you will
see
for example in linux you're going to see
the distros
in windows you'll see windows
version is going to be the version of
get this
and this is the version of the platform
itself of the operating system so we're
going to see here
uh version and now this actually does
give you a rather long
k you know version in some cases um
such as the mac because this is so the
darwin kernel but this is version
20.5 and it's going to vary
obviously i would think from operating
system to operating system
now the next two we look at here
the python
when i okay the first one was python
implementation
and then
the python version tuple
again these are all really just
informative that's probably one of the
key things to note about platform is it
is
all really informative stuff and now you
see here
uh the python implementation is c python
but i can actually see the version i'm
running on so this is python 3.9 so if i
go
for example if i were to do python-v
um oh i'm sorry that's running off of a
different one that's
it's running off python3 then we'll see
that there you go
so i have my python version there
and there's a couple of python things
you may have noticed off of platform
although it doesn't specifically have
them noted
then i can see like a build a branch a
compiler
a revision it's like if i put revision
on
you're gonna see oop i run it
then oh this one actually gives me a
blank so it's not giving me anything
useful back
uh sometimes you will sometimes you
won't again that's the
the positives and the negatives around
dealing with
a uh dealing with platform stuff is that
it is very
as probably one would expect very
platform specific so sometimes you're
going to get
very useful information sometimes not so
much
much like if you ever have dealt with
web applications and trying to figure
out certain browser types or things like
that
then you may have to actually do
something like this you may have to be
comparing some pretty long strings to
see
if there's a specific version that
you're looking for
luckily in the python world you get your
tuple and then you're ready to go so
you're going to know if this was you
know 2.6 or
3.5 or 3.52 or whatever it is
and so you can use that you could
actually validate your python version
for you get before you get too far
into an application and you could always
kick out and say hey
this is a python 3 application you're
running python 2. you know please
upgrade and things like that
so platform again there are there's
several other things out there
um that have various uses essentially to
them
and most of those are going to actually
come to your
come down to your system your desires
your needs
and if you notice even within platform
you can see here that there's
some things that are specific to unix to
macs to windows
or even to java and this link will be
in the show notes so that's platform
uh the next one look at is going to be
there's two of them so first i want to
do is
whoop his directory
or dur oh
uh i think it's actually i'd say
function we'll find out in a second
whoop
nope it is just a path like that
there we go uh let me clear this
and now let's take a look at what cis
path
actually returns to us what we're
getting from the syspath this
is our lookup so this is where
python and this becomes pretty useful uh
actually pretty critical
this is where python looks for imported
packages
and we haven't gone into this too much
and we will touch on it but for example
if you look here when we import sys and
platform
those this is where it's looking for all
of those things
so i could actually import
uh let's see what if i do
let's do
something very simple so we'll play
around with this for real quick so we're
going to do
let's just pick one doesn't matter which
so we'll do this
and this will be uh this will be mod
example
and mod example there we go
we're going to just create we're going
to do a little function and we're going
to call it
test function
and it's gonna be uh let's just do print
this is a test
so we're gonna just and we're gonna give
it uh we're not to give it any kind of a
parameter or anything like that so then
we're just going to print as a test
so now if we wanted to include this
somewhere else so let's go back to our
command examples
we could say import
mod example
and say from there
uh let's see where am i doing oh i'm in
the wrong place
sorry let's go back where i was uh this
was
actually platform commands so we do this
and then what did we call that
called test function so we could just
run
technically we could run test function
whoops
then we're going to see here
is it's going to complain because it's
not
saying this
uh because what we want is uh sorry we
want to do this so here we're gonna do
from
my example import
test function whoops i think it's a
lowercase
is that right yes
and what we're going to get is uh
if i run it i'm going to get that
oh i'm sorry so i'm going to take this
so from
uh i had to change my name here so i
flip this over
so because it doesn't like the hyphen
but uh from mod example then i'm gonna
do import test function and so now
uh let's clear this
oh like i said i need to do that and
here we go this is a test so that's that
one
now it's picking it up because it's in
this current directory if i move that
then if i move what i call mod example
so i just move it out of this folder now
it's going to blow up because it's not
going to be able to find it
but if i do
that and push it to
something that's in the system path like
for example
let's just put
let's do my users so if i go to my user
site packages
if i do that
oh not so i can pick it up because i
probably don't have that in the right
place
uh let's see users romney library
python python site packages let's see if
i got that right
oh it's just site pack shoot
i missed one that's what one so i'm
gonna take i need to make
that
to that slash
um i'm going to call it mod example
where do i put it
there we go
now if i run it uh
clear let's run it now it's picking up
because it is
in our system path so we can actually
add to that we can append to it as we
want to that is a dynamic value
variable that we're working with so we
can actually play around that and we can
set up our own
python libraries as needed or
specifically call
certain ones as opposed to getting into
maybe what's part of as you see a lot of
these it's part of the
python version built-in libraries that
you're going to see
so that's one thus this path actually
becomes fairly
uh really important as you get into
stuff
and with directory you can see what is
you can actually do a directory on some
of these things
and figure out what's there
so you can see like in this case um
this picked up
from our appear system platform we've
got my example
you can see that it actually picked up
test function and so you can see that
actually in the directory of things
that's in there which is what it's
looking for
so now if i added another function
which i have to actually i have to jump
on that real quick let's see so if that
was
here
and what i call that so if i add
something real quick
and i and this is just gonna be test
function
two this is
let's do this
also a test
so now this test function 2 lives out
there and now this time around
we can see oh it's not oh it's not
picking it up because i have to
specifically tell it to
so now if i do test function
did i get it right yeah i named it right
and so now we're gonna see
here so that's imported as well if i do
three then one i'm not gonna see it and
i'm gonna get an
error uh it actually gets it beforehand
up front when it's trying to import it
it's gonna say can't do it
test function 3 does not exist in my
example and you can see here
it's going to tell us exactly where it's
trying to get that from so as part of
your debugging
if you're trying to use something
particularly a third party library
you may find that things like syspath
and
actually a lot of it's just normal error
messages will be very helpful
in tracking down what it is that you
need to configure in your environment
so i'm going to wrap it up with those
for this time around
uh i went through a lot of stuff
platform basically giving you some
pretty straightforward information about
your platform
and then your directory and your system
path to figure out what
the python sees what the python's
runtime essentially is seeing and where
it's looking for some of the modules and
imports that you are going to you're
trying to pick up up here
let me move that mod example back
just so you've got something to play
with
move that to dot there we go
okay so it's back there so you can play
around with it all this will be in the
github repository
and we will just continue next time
around so
as always go out there have yourself a
great day a great week
and we will talk to you next time
you
Transcript Segments
0.46

[Music]

26.24

hello and welcome back

27.68

we're continuing our season our series

29.679

actually we're looking at

31.199

the python certification and working our

33.28

way through

34.64

numerous things that we're going to see

36

on that exam this episode we're going to

38.64

continue looking at some specific

40.32

commands

41.36

and we're going to focus on the platform

45.2

module this time around now there's a

48.16

link

49.76

that i will put in the show notes that

51.6

has got what we're looking at plus

53.76

more than a few others that are out

55.68

there but we're gonna look at a couple

57.44

of key

58.719

uh commands that are out there to start

60.32

this one off so let's start with

64.159

uh platform platform uh now this one's

67.28

got two

68.4

uh you can give it zero parameters or

70.96

there's

72.159

two others flags that you can provide

75.84

so if i do that

79.84

let's do this let's clear that first

84.84

and we'll blow it up a little bit more

91.28

so with platform uh

94.479

here we go now the first one i did if i

98.4

just do platform itself and this is

100.079

because this is what i'm on and what i'm

101.52

on is it tells me this is mac os 10

104.56

dot 16 it's a x8664 machine

108.439

i3864 bit now the second one i did

112.799

and uh let me go get what those actual

117.52

names of those are is it's whether it's

121.119

aliased or terse

124.159

alias doesn't work in all

128

uh systems essentially so that's why

130.64

we're going to find in both of these

132.8

oh let's go flip back over here when

135.04

whether we set alias to zero one

137.04

we still get the same thing we're gonna

138.8

get this guy but now the other part is

141.04

terse which is short

143.04

so the short version if we look at the

144.879

platform is going to be

146.56

our operating system if we add the long

149.52

version then it's going to add

151.28

you know what kind of a processor this

152.8

is basically this is an i386 it's an

154.879

intel chip it's a 64-bit

157.12

system so it's some additional

160.319

information we can get

161.84

oh you may use this occasionally i have

164.319

seen this where people are using it to

165.84

do maybe

167.2

maybe you've got like some scripts that

169.04

are operating system specific

171.2

or require a specific version of an

174

operating system so

175.12

you can take a look at that to make sure

176.48

you know what your platform is

178.319

you may just use it for logging just to

179.68

get an idea of what

181.44

people are using now the next one is

183.519

machine

189.04

so if you look at machine it also has

192.159

no parameters and machine

196.319

is funny enough going to give you in

198.159

this case

199.36

part of what is in the verbose version

201.519

of the

202.959

uh the platform and so this is actually

205.36

your machine right here

207.12

so you can either do the whole thing or

209.36

you can actually pull that out

210.4

specifically we're going to see

211.519

something

212

similar with

215.04

processor processor

223.36

so we see here with our processor

225.2

processor

226.48

it's going to be i386 and you see that's

229.599

there so this

230.319

actually this platform happens to be

233.36

the essentially the operating system

237.36

the machine the processor processor

241.04

and then you're going to find out

244.72

very similarly oh

247.76

let me paste that properly

252.4

and then we do system

256.72

you can see that uh system is going to

259.6

give you the operating system name so

261.359

i'm sorry that's not saying that's the

262.56

last bit but it's not

263.759

so system this is essentially the

265.199

operating system name

267.04

so it may be and i forget what you'll

269.68

get on some other stuff i think you will

271.28

see

272.4

for example in linux you're going to see

273.759

the distros

275.44

in windows you'll see windows

278.8

version is going to be the version of

283.919

get this

290.639

and this is the version of the platform

292.96

itself of the operating system so we're

294.639

going to see here

296.479

uh version and now this actually does

298.639

give you a rather long

300.4

k you know version in some cases um

303.68

such as the mac because this is so the

305.44

darwin kernel but this is version

307.8

20.5 and it's going to vary

310.96

obviously i would think from operating

313.6

system to operating system

315.52

now the next two we look at here

320.4

the python

324.479

when i okay the first one was python

326.639

implementation

328.96

and then

335.919

the python version tuple

342.56

again these are all really just

344.24

informative that's probably one of the

345.84

key things to note about platform is it

347.6

is

348.56

all really informative stuff and now you

352.4

see here

353.68

uh the python implementation is c python

357.52

but i can actually see the version i'm

358.96

running on so this is python 3.9 so if i

361.84

go

362.4

for example if i were to do python-v

366.16

um oh i'm sorry that's running off of a

368.16

different one that's

370

it's running off python3 then we'll see

372.639

that there you go

373.6

so i have my python version there

378

and there's a couple of python things

379.759

you may have noticed off of platform

381.84

although it doesn't specifically have

383.52

them noted

387.039

then i can see like a build a branch a

389.36

compiler

390.88

a revision it's like if i put revision

394.56

on

394.96

you're gonna see oop i run it

399.36

then oh this one actually gives me a

403.039

blank so it's not giving me anything

404.24

useful back

405.68

uh sometimes you will sometimes you

407.12

won't again that's the

410.24

the positives and the negatives around

412.88

dealing with

413.599

a uh dealing with platform stuff is that

416.639

it is very

417.84

as probably one would expect very

419.52

platform specific so sometimes you're

421.52

going to get

422.8

very useful information sometimes not so

424.8

much

426

much like if you ever have dealt with

429.28

web applications and trying to figure

430.8

out certain browser types or things like

432.4

that

433.36

then you may have to actually do

435.759

something like this you may have to be

436.8

comparing some pretty long strings to

438.639

see

439.039

if there's a specific version that

441.039

you're looking for

442.4

luckily in the python world you get your

444.56

tuple and then you're ready to go so

446.4

you're going to know if this was you

447.52

know 2.6 or

449.199

3.5 or 3.52 or whatever it is

452.639

and so you can use that you could

453.919

actually validate your python version

455.599

for you get before you get too far

457.039

into an application and you could always

458.8

kick out and say hey

460.72

this is a python 3 application you're

462.479

running python 2. you know please

464.639

upgrade and things like that

467.68

so platform again there are there's

470.4

several other things out there

472.479

um that have various uses essentially to

476

them

476.319

and most of those are going to actually

477.84

come to your

479.52

come down to your system your desires

483.12

your needs

483.919

and if you notice even within platform

486.24

you can see here that there's

487.36

some things that are specific to unix to

489.52

macs to windows

491.12

or even to java and this link will be

495.12

in the show notes so that's platform

498.24

uh the next one look at is going to be

503.039

there's two of them so first i want to

504.4

do is

507.12

whoop his directory

511.599

or dur oh

523.2

uh i think it's actually i'd say

525.2

function we'll find out in a second

526.64

whoop

530.88

nope it is just a path like that

535.12

there we go uh let me clear this

540.16

and now let's take a look at what cis

542.959

path

544.32

actually returns to us what we're

547.44

getting from the syspath this

548.959

is our lookup so this is where

552.399

python and this becomes pretty useful uh

554.88

actually pretty critical

555.92

this is where python looks for imported

558.24

packages

559.44

and we haven't gone into this too much

562

and we will touch on it but for example

565.12

if you look here when we import sys and

568.16

platform

569.2

those this is where it's looking for all

572.32

of those things

574.32

so i could actually import

577.44

uh let's see what if i do

582.959

let's do

586.32

something very simple so we'll play

587.68

around with this for real quick so we're

589.12

going to do

591.04

let's just pick one doesn't matter which

592.88

so we'll do this

594.64

and this will be uh this will be mod

597.839

example

601.519

and mod example there we go

605.36

we're going to just create we're going

608.48

to do a little function and we're going

609.76

to call it

613.519

test function

617.68

and it's gonna be uh let's just do print

624.88

this is a test

628.399

so we're gonna just and we're gonna give

630.16

it uh we're not to give it any kind of a

633.92

parameter or anything like that so then

635.519

we're just going to print as a test

637.279

so now if we wanted to include this

640.72

somewhere else so let's go back to our

642.32

command examples

643.76

we could say import

648.24

mod example

652.079

and say from there

657.519

uh let's see where am i doing oh i'm in

660.16

the wrong place

660.959

sorry let's go back where i was uh this

664.16

was

664.48

actually platform commands so we do this

668.16

and then what did we call that

671.519

called test function so we could just

674.56

run

677.12

technically we could run test function

680.16

whoops

685.76

then we're going to see here

689.839

is it's going to complain because it's

693.279

not

693.68

saying this

703.44

uh because what we want is uh sorry we

706.72

want to do this so here we're gonna do

708.32

from

709.36

my example import

714

test function whoops i think it's a

716.72

lowercase

717.36

is that right yes

728.8

and what we're going to get is uh

731.92

if i run it i'm going to get that

735.519

oh i'm sorry so i'm going to take this

738.16

so from

738.72

uh i had to change my name here so i

740.399

flip this over

741.76

so because it doesn't like the hyphen

743.279

but uh from mod example then i'm gonna

745.6

do import test function and so now

748.639

uh let's clear this

753.12

oh like i said i need to do that and

756.24

here we go this is a test so that's that

758.48

one

759.279

now it's picking it up because it's in

761.92

this current directory if i move that

768.48

then if i move what i call mod example

773.2

so i just move it out of this folder now

775.92

it's going to blow up because it's not

777.44

going to be able to find it

778.88

but if i do

782.8

that and push it to

786.32

something that's in the system path like

789.12

for example

790.959

let's just put

795.36

let's do my users so if i go to my user

798.32

site packages

802.399

if i do that

805.519

oh not so i can pick it up because i

807.04

probably don't have that in the right

812.839

place

816.399

uh let's see users romney library

819.92

python python site packages let's see if

822.56

i got that right

830.8

oh it's just site pack shoot

834.56

i missed one that's what one so i'm

836.72

gonna take i need to make

840.839

that

842.24

to that slash

847.199

um i'm going to call it mod example

849.279

where do i put it

850.56

there we go

854.72

now if i run it uh

857.92

clear let's run it now it's picking up

861.44

because it is

862.079

in our system path so we can actually

865.44

add to that we can append to it as we

866.88

want to that is a dynamic value

869.199

variable that we're working with so we

871.92

can actually play around that and we can

873.199

set up our own

874.88

python libraries as needed or

877.36

specifically call

878.48

certain ones as opposed to getting into

881.519

maybe what's part of as you see a lot of

883.44

these it's part of the

885.04

python version built-in libraries that

887.68

you're going to see

889.519

so that's one thus this path actually

891.92

becomes fairly

892.959

uh really important as you get into

894.959

stuff

896.079

and with directory you can see what is

898.88

you can actually do a directory on some

900.24

of these things

901.279

and figure out what's there

904.399

so you can see like in this case um

908.079

this picked up

911.36

from our appear system platform we've

914.24

got my example

915.44

you can see that it actually picked up

918.48

test function and so you can see that

920.639

actually in the directory of things

921.839

that's in there which is what it's

923.04

looking for

923.6

so now if i added another function

927.6

which i have to actually i have to jump

930.16

on that real quick let's see so if that

931.44

was

933.44

here

937.199

and what i call that so if i add

939.759

something real quick

943.92

and i and this is just gonna be test

948

function

952.839

two this is

955.839

let's do this

959.12

also a test

963.36

so now this test function 2 lives out

965.279

there and now this time around

966.8

we can see oh it's not oh it's not

968.88

picking it up because i have to

969.759

specifically tell it to

972.959

so now if i do test function

980.079

did i get it right yeah i named it right

981.839

and so now we're gonna see

983.36

here so that's imported as well if i do

986.48

three then one i'm not gonna see it and

989.839

i'm gonna get an

990.639

error uh it actually gets it beforehand

993.04

up front when it's trying to import it

994.72

it's gonna say can't do it

996.399

test function 3 does not exist in my

998.48

example and you can see here

1000.88

it's going to tell us exactly where it's

1002.079

trying to get that from so as part of

1003.6

your debugging

1004.8

if you're trying to use something

1006.48

particularly a third party library

1009.04

you may find that things like syspath

1011.839

and

1012.48

actually a lot of it's just normal error

1015.04

messages will be very helpful

1017.04

in tracking down what it is that you

1018.88

need to configure in your environment

1022.24

so i'm going to wrap it up with those

1024.24

for this time around

1025.36

uh i went through a lot of stuff

1026.72

platform basically giving you some

1029.439

pretty straightforward information about

1031.36

your platform

1032.559

and then your directory and your system

1035.039

path to figure out what

1036.559

the python sees what the python's

1039.679

runtime essentially is seeing and where

1042.64

it's looking for some of the modules and

1044.88

imports that you are going to you're

1046.48

trying to pick up up here

1048.4

let me move that mod example back

1053.679

just so you've got something to play

1055.76

with

1059.679

move that to dot there we go

1063.12

okay so it's back there so you can play

1064.32

around with it all this will be in the

1066

github repository

1067.28

and we will just continue next time

1070.24

around so

1071.2

as always go out there have yourself a

1072.88

great day a great week

1074.48

and we will talk to you next time

1092.88

you