Python is a high level, interpreted and general-purpose dynamic language that focuses on code readability. This is used in many organizations as this supports multiple. This also performs automatic memory management. This is one of the world’s most popular, in-demand languages. This is for many reasons:
- It is very easy to learn.
- It is a multi-purpose language.
- This are numerous modules and libraries.
The fact that this can support the vast majority of third-party modules. There are some quite interesting modules that are considered worthy. In this article’s, some of the modules are discussed which will come in easy no matter if you are a beginner or a pro. As most of them are third-party modules, they don’t come in-built with Python and are needs to install. Installation of third-party modules can be seen here.
NOTE: Some of these code may not work in Python 2, it is a bit differ by python 3. Hence I recommend you to use Python 3.
Emojis make a way to express and enhance simple boring texts. Now, the same can be used in Python programming too. Yes, really! You now have the power to use emojis in your python code. For this, emoji the module must 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
from emoji import emojize print(emojize(":thumbs_up:"))
Use the emoji cheat sheet to find emojis
Alternatively, encode() the function can be used from the emojis module to convert Unicode to emojis:
import emojis emojified = emojis.encode("There is a :snake: in my boot !") print(emojified)
Hope you try it!
How do I
If you have any problem? want to visit StackOverflow without leaving the terminal?
Install the howdoi python module by:
pip install howdoi
Or install it by using the command:
python setup.py install
Ask your doubt
howdoi make trees in Pythonhowdoi commit in git
howdoi use Howdoi in Python
we can import the entire Wikipedia.
pip install wikipedia
you can use it as:
import wikipediaresult = wikipedia.page("stackoverflow")print(result.summary)
If you want to take sentences from the summary, there is an argument just pass it to the
import wikipediaprint(wikipedia.summary("Debugging", sentences = 2))
Have you ever wondered? that how to dis assemble any python source code, then you can do it with python a python module, this give the figures if functions that made in the code, number of strings, etc.
# This will import # dis module import dis def test(number): return (str(number)+str(number)) def newFunc(string): print("Hello", string) # This will display the # disassembly of test(): dis.dis(test) # This will display the # disassembly of newFunc() dis.dis(newFunc)
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!
This is a funny type of module in python, it is like easter egg in python which is used by GOOGLE search engines, the main purpose to add this module is to amuse the readers.
Install it with:
pip install antigravity
And then type:
import antigravity def main(): antigravity.fly() if __name__=='__main__': main()
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/.
It another python module which used to terminate any program that is running in your PC, we can terminate any program by using the function sys.exit(). It is a built-in module so you have to use PIP.
# This will import # sys module import sys while True: print("Type 'exit' to exit") response = input() if response == "exit": print("Exiting the program") sys.exit() print("You typed", response)
If the input is :
The output will be :
Type 'exit' to exit You typed resolvemyquery Type 'exit' to exit Exiting the program
urllib is a python module used to handles URLs. It is also used to fetch URLs ( Uniform Resource Locators ). It has a function called urlopen of different protocols like HTTPS, HTTP.
urllib.request for opening and reading. urllib.parse for parsing URLs urllib.error for the exceptions raised urllib.robotparser for parsing robot.txt files
# This will import urlopen # class from urllib module from urllib.request import urlopen page = urlopen("http://geeksforgeeks.org/") print(page.headers)
The will 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
# This will import urlopen # class from urllib module from urllib.request import urlopen page=urlopen("http://resolvemyquery.com/") # Fetches the code # of the web page content = page.read() print(content)
“Turtle” is a Python modules like a drawing board and tkinte module is also used, which takes command to draw all over it! This module comes in built with Python so there is no need of “”PIP.
# This will import turtle module import turtle myTurtle = turtle.Turtle() myWin = turtle.Screen() # Turtle to draw a spiral def drawSpiral(myTurtle, linelen): myTurtle.forward(linelen) myTurtle.right(90) drawSpiral(myTurtle, linelen-10) drawSpiral(myTurtle, 80) myWin.exitonclick()