Daily Python
Published in

Daily Python

Interesting Python modules for Beginners | Daily Python #24

This article lists a few interesting modules to play around whilst learning Python.

This article is a part of Daily Python challenge that I have taken up for myself. I will be writing short python articles daily.

Requirements:

  1. Python 3.0
  2. Pip

Install the following packages:

  1. pyperclip — Library to handle clipboard content
  2. emoji — Library to generate emojis
  3. howdoi — Library to guide through python
  4. antigravity
  5. wikipedia — Library to fetch wikipedia content
  6. dis — Library to uncover how Python works internally

Pyperclip

I have discussed how to handle clipboard content using ‘pynput’. This library is an alternative to that and quite easy to implement. We just need to use the copy and paste functions to copy from or to write to the clipboard. Below is an example of how you can use ‘pyperclip’.

#1. Pyperclip
import pyperclip
pyperclip.copy('Heyyy this is being copied to clipboard')
print(pyperclip.paste())

Emoji

This library makes it easy to create emojis in Python. If you are building a chatbot and want to recommend emojis based on text, then you can suggest relevant emojis by applying regular expressions on the input string. The ‘emojize’ function returns the Unicode characters for the given emoji name.

#2. Emoji
from emoji import emojize
print(emojize(':thumbs_up:'),emojize(':snake:'))

How Do I?

This library is quite handy if you want to avoid going to google and searching for how to do a particular operation in Python. You can directly access this module through the terminal or you can import it in a Python script and pass the required query. The following code snippet demonstrates how to open a file in Python using ‘howdoi ’module.

#3. Howdoi
from howdoi import howdoi
query = "open a file in python"
parser = howdoi.get_parser()
args = vars(parser.parse_args(query.split(' ')))
output = howdoi.howdoi(args)
print(output)

Antigravity

This library opens up a webpage that contains comics related to python. The reason this module is here is that 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.

#4. Antigravity
import antigravity

Wikipedia

As the name suggests, this module is built to easily access Wikipedia pages from Python. If you are building an application that needs to access Wikipedia pages, then this module is quite handy and easy to integrate into any application. You can also get the summary of the page by using the summary attribute of the Wikipedia page.

#5. Wikipedia
import wikipedia
page = wikipedia.page("Python")
print(page.summary)

Dissembler Python

In simple terms, this module shows what happens under the hood of the Python interpreter. The dis module supports the analysis of CPython bytecode by disassembling it. The CPython bytecode which this module takes as an input is defined in the file Include/opcode.h and used by the compiler and the interpreter.

CPython implementation detail: Bytecode is an implementation detail of the CPython interpreter. No guarantees are made that bytecode will not be added, removed, or changed between versions of Python. The use of this module should not be considered to work across Python VMs or Python releases.

#6. Dissemble Python
import dis
def myfun(num):
return('Number to string : ',str(num))
dis.dis(myfun)

I hope this article was helpful, do leave some claps if you liked it.

Follow the Daily Python Challenge here:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store