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
[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