[no audio]
Friends, we know that Python is having lot of modules, right,
and here I am going to take one of the modules as 'platform'
module. Then what is the use of this 'platform' module? See 'platform'
module is useful to access underlying platform's data such
as hardware, operating system and interpreter version info,
and here you don't need to worry how to get this information.
I mean 'platform' is a module.
Right. See by simply typing from your command line, because
you are at initial stage, right,
what you will do, you will go to Python, then simply there
you will type suppose simply 'help("modules")',
[no audio]
and you're going to get list of modules here just assume
that. From the list of modules you are going to select anyone
of that. Then how you will come to know
what is the usage of that module, right?
You will see in the documentation itself
what is the usage of that module, right?
You have a lot of modules here. Just assume that you are going
to select one of the modules called 'csv',
or one of the modules called, let me take,
[no audio]
'getpass'. Then what is the usage of that? It is there with
your Python documentation itself.
I will show you that, just wait.
Right. Fine. Now guys, already we have seen if you want to use
any module in your current script,
right, what we are doing? Simply we are importing that, right.
So how to use any module in a script.
So in our case, 'platform', right?
See you can use simply 'import platform'.
This is one way, and already we have seen. You can also import
'import platform as pt'. That means you are aliasing your module,
or you are renaming your module. Instead of using 'platform
as platform'.
Now, we are using 'as pt'.
Right. Yes, it is possible.
You can modify the default module name, in your current script
not with your Python, right. Or this is also one more way, right
'from platform',
you can import all functions and variables, right?
See you know module is nothing but, it is simply a Python
script which consists of some functions, classes and variables.
So, all directly you can import in this way.
Then suppose from 'platform' module
I need only 'system' and 'platform' functions,
so inside of this we have different things. Just assume that
I know suppose 'system' and 'platform' are required
from your 'platform' module,
then I can import only those two things in this way also,
right. So as a fresher, right, you are at beginner level, then
try to use first in this way. While going forward
we will see this one, this one, this one, everything we will
see. Right. Fine. Then, just now we discussed that 'platform'
is a module which consists of some functions and variables.
Then how you can list all those things? Guys, with your Python
there is a default function called 'dir', with that you can
list all the functions and variables
which are there with your 'platform' module, not only with your
'platform' module with any module, right?
Then you can use simply, from script
you can 'print(dir(platform))', or from command line directly
you can run 'dir(platform)'.
I will show you both the procedures. And then how you can
get documentation for your 'platform' module,
not only 'platform', any module, right?
Simply you can run 'help("platform")' from your command line or
from script you can run 'print(help(platform))', right?
Let me open first your command line, right?
So guys, just assume that I want to work with 'platform' module,
then what I have to do? First thing it may be command line
or it may be your Python script,
you have to import it first.
So, I am going to import it, 'import platform'.
Yes, just now you imported 'platform'. Then immediately my action
is, I want to know what are all the operations, or what are
all the functions and variables are there with your 'platform'.
Then simply run 'dir(platform)'.
You will get a lot of things here.
Each and everything is some separate operation, right?
You can assume each and everything is like one operation,
right. But you don't know what is the purpose of each and everything here.
We have a lot of values as a list, right. See that how many
values you have, you can find out using length of your list,
72 operations are there, suppose.
Right. There is a specific operation with each and every value which
is there in your list. After running 'dir(platform)'
you are getting different things no, so here for each and
everything there is a specific operation, but how you will
come to know what is the usage of this each and everything, right?
So, guys you are at initial stage. What you have to do immediately,
immediately after importing your 'platform' to list all available
operations or simply functions and variables you are running
'dir(platform)' module, then same way just run 'help()'
[no audio]
'platform', and it is going to give a document, right. See that,
'This module tries to retrieve as much platform identifying data.'
That means some hardware information, right, interpreter
information, something like that.
Now, if you go with all the functions, guys as of now this
module is implemented with class concept,
I mean OOPS concept, but you don't worry as of now you
don't know OOPS, right.
Finally, we'll come to know how to create a module with OOPS,
or with only functions, or with only variables, for time being
don't worry about class, right.
So somewhere, just go down, guys
not only with this module, any module, as of now
don't observe this 'classes'.
Okay. Just go down. Go down. See here,
first go down completely from top to down.
[no audio]
Now you are getting somewhere here functions. Now,
try to understand this one, one by one.
There is a 'architecture' function from your 'platform',
then what is the usage of that?
It is going to give some architecture information. You just
go to document one by one so that you will get,
right. See -
machine(), node(), platform(), right?
You have a lot of things here.
Just go through that one by one.
What is the Python version you have on your host,
your 'platform' module will fetch that.
Right. Then
what is the operating system type?
[no audio]
See that, 'system()', right?
That's it.
'DATA', as of now data is 'null'.
Nothing is there. It is displaying 'null'.
You don't worry about this value as of now. Actually it is a
simple single variable like from your mathematic function,
'pi' is a pi value, right?
same way 'DEV_NULL' is one variable. That's it.
Right. See same way you can run your entire thing
from your script as well.
Let me do it, the script,
[no audio]
so my requirement is,
[no audio]
so 'working_with_modules.py'. Fine.
[no audio]
I want to work with 'platform' module, then what I have to do?
I need to import, first 'import platform', right. Then immediately
I want to see list of operations or list of functions and
variables with your 'platform'. See from command line directly
you're running 'dir(platform)'.
But if it is a script you have to print that then only it
will show you on your output.
Let me save it, and in your Sublime Text to run your Python
script just press 'Ctrl + B'.
[no audio]
'Ctrl + B' if you press, you will get the list of all operations.
I mean 'Ctrl + B' is just to run your Python script. Same way
I need to know the documentation as well,
right. Simply 'print(help(platform))'.
That's it. Run it and see the output.
[no audio]
So, it is giving at a time your entire document, right?
You can copy and save it into some file and you can
go through that line by line, right. But better is, always
guys if you want to get any help
try to use only command line.
So always try to write a code in Python script and from command
line try to get your help.
Right. Fine.
So, let me go with some one-by-one operations, but not all,
some of them which are very, very important.
But while going forward I will cover most of the operations
which are required for our real-time cases. Right. Fine.
Let me do this one.
Right. So, guys
I want to know what type of operating system you are using.
Then for that in 'platform'
there is a function called, see that. '.system'.
[no audio]
Run the script and see the output, Windows.
So now I can see that I can write, I can write like, "This is,
[no audio]
let me do 'f 'string "This is", so this is the operation guys.
You can write in, you have to write in curly braces.
[no audio]
'os', Windows OS. That's it. Now see the output. Because of
'platform.system()' you're getting information as Windows. Same script
if you run on your Unix-like systems, you will get
that operating system name.
Right. Then,
let me take one more thing.
I want to see what is the python version is there on this
host, right?
See that. 'print(
[no audio]
"Python version is", let me run from your 'platform'.
Right. So guys here you may get confused, why we are using
parentheses. Right. Something wrong, yeah.
[no audio]
After curly brace you have to write quotation.
Fine. You may get some confusion.
See here I'm using parentheses, and in this parenthesis, I'm
not writing anything.
Sometimes you have to write sometimes no need to write.
You should not write actually, right?
See, this is a function,
that's why I'm writing a parenthesis. But how you will come
to know whether that is a function or not? Again in your documentation
you will have that. See that, 'system()', with parentheses,
and here in documentation
they are not writing anything means, no need to provide any
value while using this
'system()' function. Otherwise, you can do one more
thing. Simply run 'platform',
that is the module, right, from that I'm using system.
I don't know system is a variable or a function, then simply
I will run in this way. Then see that it is showing that function.
Then now just include parentheses. Because you are at initial
stage you have to do all these steps.
Right. Fine.
[no audio]
Now, you can also get your Python version in terms
of, there are some different values are there guys, right?
Okay. You can also get your Python version in terms of two
tuple. Now see that if I run that how I am going to get. Simply
I am running 'print', simply I am going to use this.
So, this is also a function, so I am going to do 'platform.'.
'.', see the last output, you're getting as a tuple, right
major, minor, and release versions, right?
That's it. So here you are getting as a string, and but here you
are getting as a tuple. Inside a tuple, again
your data is string only. See that. Quotations are there.
[no audio]
Right. Then,
let me go and run some more examples from your 'platform'.
So, what I want to do is, so now I can run directly from your
terminal. That's better.
[no audio]
Let me clear my screen first.
So I'm entering into Python.
I am going to 'import platform'.
[no audio]
Let me simply print,
so you can do this even in your script also guys, but I
am directly, I want to show you the result directly,
that's why I'm running here.
So, I want to know what is the machine information. See that
AMD64. Right. Same you just run on your Unix-like system
also. You will get some your, Unix-like systems some 86 X 64,
something like that. Right. Then,
what is the release?
[no audio]
Windows 10. Right. Then see that, there is a 'platform.platform'
module, I mean function through which you're going to get
entire information, your Windows operating system 10, and
it's SP packs, something like that.
Right. Then, I want to see the architecture. Guys, you don't need to worry
how you can select this function names from your
module. You know this one,
run this, see the operations. Now,
I want to print architecture of this operating system.
So simply 'platform.', there is something operation called
'architecture'. You can search here somewhere,
[no audio]
without underscores from where we have, yeah, somewhere here
we have 'architecture', right?
[no audio]
That's it. See that '64-bit', 'Windows PE'.
[no audio]
Right. Then what is the processor you are using?
Somewhere we have 'processor'. Observe that.
[no audio]
Right. Just copy it.
[no audio]
That's it.
[no audio]
Fine. Now finally, let me go with your
[no audio]
'platform.node'.
What is the node for this? So here, because this is my Desktop
I am getting this as my node, right. You just try to run this
on Unix-like systems.
You just observe that what you are going to get. Just your
'node' information.
Right. Then let me run last one here. See that, 'uname'
See in your Unix-like systems
also you're having 'uname' command.
If you run there 'uname' command you are going to get
entire information about your
operating system, right.
See here also Python is giving 'platform.uname'
What is the system name,
right, the node, release, version, machine, processor, right,
everything it is going to give with one single command.
[no audio]
Right. Fine. Okay guys, this is about simply your 'platform'
module. So, we will see step by step different modules
with examples, okay.
Okay guys, thank you for watching this video.
[no audio]