Standard Library
Following is the link to get info about all the Modules in Standard library.
Following example show the syntax of importing "time" module from Standard library and doing a simple work..
3rd Party Libraries
Let's see an example of a 3rd party library called "rich", 1st it needs to be installed..
pip3 install rich
If you noticed, the file I created is saved in /home/roshan/Python-Net-Eng/.venv/lib/python3.8/site-packages since this is the folder which the rich library is downloaded and installed. This is because when it tries to import there are certain locations it looks in including the current working directory. If it could not find it in those locations, script is not compiled.
Following script shows which locations it looks to import the modules.
Import only a Module from a Library
Above example of importing rich library actually imported whole library, but in case if you need only a specific module to be imported from a library, following is the syntax.
But if we need to use the default print() function along with it, we can use an alias to the imported function like the following example.
No comments:
Post a Comment