Python is a high level, interpreted and general-purpose dynamic programming language that focuses on code readability. It is used in many organizations as it supports multiple programming paradigms. It also performs automatic memory management. It is one of the world’s most popular, in-demand programming languages. This is for many reasons:
- It’s easy to learn.
- It’s super versatile.
- It has a huge range of modules and libraries.
The fact that it can support the vast majority of third-party modules, it acts as a cherry on the cake. There are some quite interesting modules that are considered worthy of sharing with others. In this article, some of the modules are discussed which will come in handy no matter if you are a beginner or a professional. As most of them are third party modules, they don’t come in-built with Python and are needed to install. Installation of third party modules can be seen here.
NOTE: Some of these code may not work in Python 2. Hence I strongly recommend you to try them in Python 3.
This module was created to enable cross-platform copy-pasting in Python which was earlier absent. The
pyperclip module has
paste() functions that can send text to and receive text from your computer’s clipboard. Sending the output of your program to the clipboard will make it easy to paste it on an email, word processor, or some other software.
Pyperclip does not come with Python. To install it, follow the directions for installing third party modules. After installing the module, enter the following into IDE:
Of course, if something outside your program changes the clipboard contents, the
paste() function will return it. For example, if this sentence is copied to the clipboard and then
paste() is called, the output would look like this:
‘For example, if this sentence is copied to the clipboard and then paste() is called, the output would look like this:’
Emojis have become a way to express and to enhance simple boring texts. Now, the same gems can be used in Python programs too. Yes, really! You now have the ultimate power to use emojis in your code. For this,
emoji module is needed to be installed.
In terminal. Use:
pip install emoji
To upgrade to the latest packages of emojis. Here’s how it can be done:
pip install emoji --upgrade
Use the emoji cheat sheet to find your favorite emoji.
encode() function can be used from emojis module to convert Unicode to emojis:
Hope you try it!
Stuck on a coding problem? Wish to visit StackOverflow without leaving the terminal? With
howdoi, you can do it!
Install the howdoi module by:
pip install howdoi
Or install from Python by:
python setup.py install
Ask whatever question you have and it will try it’s best to answer it.
From now, you don’t need to open those browsers for a quick search and get those hefty amounts of ads and distractions. Just howdoi!
As if howdoi wasn’t enough, we can now import the entire Wikipedia! Yes, We can now import Wikipedia in Python using
Wikipedia module. Use the incessant flow of knowledge with Python for daily needs.
Install it as:
pip install wikipedia
And use it as:
If you wish to get a particular number of sentences from the summary, just pass that as an argument to the
New types at runtime
This can create new types in a fully dynamic way. It’s the same as creating a class but something new which you can show to your friends.
<class '__main__.NewType'> hello newtype
The above code is same as:
<class '__main__.NewType'> hello newtype
Probably not the best module but still worth a try!
Ever wondered what python does under the hood? With the standard library module dis, you can look easily.
Result: 8 0 LOAD_GLOBAL 0 (str) 3 LOAD_FAST 0 (number) 6 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 9 LOAD_GLOBAL 0 (str) 12 LOAD_FAST 0 (number) 15 CALL_FUNCTION 1 (1 positional, 0 keyword pair) 18 BINARY_ADD 19 RETURN_VALUE 3 0 LOAD_GLOBAL 0 (print) 3 LOAD_CONST 1 ('Hello') 6 LOAD_FAST 0 (string) 9 CALL_FUNCTION 2 (2 positional, 0 keyword pair) 12 POP_TOP 13 LOAD_CONST 0 (None) 16 RETURN_VALUE
That’s overwhelming and also amazing!
The reason this module is here is because this is quite fun! It’s basically an easter egg in Python 3 which is used in Google App Engines. It was added to Google App Engines just as a medium to amuse the users.
Install it with:
pip install antigravity
And then type this in your IDE to see the magic:
This opens up a page in your web browser which contains a comical abstract of Python developed for your delight. Congratulations! You know have the ability to fly or for now the ability to visit this link https://xkcd.com/353/.
You may have used the sys module before but did you know you could exit your program early using it? We can cause the program to terminate by calling the
sys.exit() function. Since this function is in the
sys module, firstly, the
sys module should be imported. This is not a third party module and comes built-in with Python so there is no need to install it.
If the input is :
"Geeky" "GeeksforGeeks" "exit"
The output will be :
Type 'exit' to exit You typed Geeky Type 'exit' to exit You typed GeeksforGeeks Type 'exit' to exit Exiting the program
Urllib module is the URL handling module for python. It is used to fetch URLs (Uniform Resource Locators). It uses the urlopen function and is able to fetch URLs using a variety of different protocols.
Urllib is a package that collects several modules for working with URLs, such as:
- urllib.request for opening and reading.
- urllib.parse for parsing URLs
- urllib.error for the exceptions raised
- urllib.robotparser for parsing robot.txt files
The output would be:
Server: Apache Strict-Transport-Security: max-age=3600; includeSubDomains Access-Control-Allow-Credentials: true X-Frame-Options: DENY X-Content-Type-Options: nosniff Content-Type: text/html; charset=UTF-8 X-Akamai-Transformed: 9 - 0 pmb=mRUM,3 Vary: Accept-Encoding Cache-Control: must-revalidate, max-age=3, s-maxage=21600 Date: Fri, 04 Oct 2019 04:57:37 GMT Transfer-Encoding: chunked Connection: close Connection: Transfer-Encoding Server-Timing: cdn-cache; desc=HIT Server-Timing: edge; dur=1
You can also see the coding of the website by using
Yes, a turtle can be imported. Don’t worry it’s not slow. Turtle is a Python module to draw. It has a huge application and a number of methods which you can learn about in here. But with just a few basics, pretty cool stuff can be done. This module comes built-in with Python so there is no need to install it.
- Python Modules
- Reloading modules in Python
- Python | Opaque Pointers in C extension modules
- Python | Play a video using OpenCV
- Dividing a Large file into Separate Modules in C/C++, Java and Python
- Python | Play a video in reverse mode using OpenCV
- Interesting facts about strings in Python | Set 1
- 10 Interesting Python Cool Tricks
- Interesting facts about strings in Python | Set 2 (Slicing)
- Interesting Python Implementation for Next Greater Elements
- Py-Facts - 10 interesting facts about Python
- Interesting Facts About CSS
- Interesting Facts About PHP
- Interesting Facts in C Programming | Set 2
- Interesting Infinite loop using characters in C
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.