Table of Contents
1. Show WiFi password
2. Convert video to GIF
Installation
Code
3. Desktop Reminder
4. Custom shortcut keys
5. Convert text to PDF
6. Generate QR code
7. Translation
8. Google Search
9. Extract audio
10. Generate short links
Home Backend Development Python Tutorial These Python operations are amazing and practical!

These Python operations are amazing and practical!

May 03, 2023 am 09:52 AM
python code wifi password

These Python operations are amazing and practical!

Hello, everyone, I am a rookie.

Do you often encounter this dilemma? When relatives and friends come to your home as guests, they ask for the WiFi password, and then they rummage through the cabinets and ask around but can’t find it.

Today, I will introduce to you some little-known operations of Python.

These operations are not to show off skills, but are really practical!

1. Show WiFi password

We often forget the WiFi password, but whenever relatives and friends come home and ask for the WiFi password, we don’t know how to start.

Here is a trick, we can list all the devices and their passwords.

import subprocess #import required library
data = subprocess.check_output(['netsh', 'wlan', 'show', 'profiles']).decode('utf-8').split('n') #store profiles data in "data" variable
profiles = [i.split(":")[1][1:-1] for i in data if"All User Profile"in i] #store the profile by converting them to list
for i in profiles:
# running the command to check passwords
results = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('n')
# storing passwords after converting them to list
results = [b.split(":")[1][1:-1] for b in results if"Key Content"in b]
try:
print ("{:<30}|{:<}".format(i, results[0]))
except IndexError:
print ("{:<30}|{:<}".format(i, ""))
Copy after login

2. Convert video to GIF

In recent years, GIF has become a craze. Most of the popular social media platforms provide users with a variety of GIFs to express their thoughts in a more meaningful and understandable way.

Many students have taken great pains to convert videos into GIFs, and have stepped into many pitfalls in the process.

With Python, you can solve it with just a few lines of code!

Installation

pip install moviepy
Copy after login
Copy after login

Code

from moviepy.editor import VideoFileClip
clip = VideoFileClip("video_file.mp4") # Enter your video's path
clip.write_gif("gif_file.gif", fps = 10)
Copy after login

3. Desktop Reminder

When we are working on projects or other things, we may forget some important Things that we can remember by seeing a simple notification on the system.

With the help of python, we can create personalized notifications and can schedule them at a specific time.

Installation

pip install win10toast, schedule
Copy after login

Code

import win10toast
toaster = win10toast.ToastNotifier()
import schedule
import time
def job():
toaster.show_toast('提醒', "到吃饭时间了!", duration = 15)
schedule.every().hour.do(job)#scheduling for every hour; you can even change the scheduled time with schedule library
whileTrue:
schedule.run_pending()
time.sleep(1)
Copy after login

4. Custom shortcut keys

Sometimes, we need to enter some words frequently at work. Wouldn’t it be interesting if we could automate our keyboards to write these frequently used words using only abbreviations?

Yes, we can make it possible with Python.

Installation

pip install keyboard
Copy after login

Code

import keyboard
#press sb and space immediately(otherwise the trick wont work)
keyboard.add_abbreviation('ex', '我是一条测试数据!') #provide abbreviation and the original word here
# Block forever, like `while True`.
keyboard.wait()
Copy after login

Then, enter ex and a space anywhere to quickly complete the corresponding statement!

5. Convert text to PDF

We all know that some notes and books available online exist in pdf form.

This is because PDF can store content in the same way regardless of platform or device.

So, if we have text files, we can convert them into PDF files with the help of python library fpdf.

Installation

pip install fpdf
Copy after login

Code

from fpdf import FPDF
pdf = FPDF()
pdf.add_page()# Add a page
pdf.set_font("Arial", size = 15) # set style and size of font
f = open("game_notes.txt", "r")# open the text file in read mode
# insert the texts in pdf
for x in f:
pdf.cell(50,5, txt = x, ln = 1, align = 'C')
#pdf.output("path where you want to store pdf file\file_name.pdf")
pdf.output("game_notes.pdf")
Copy after login

6. Generate QR code

We often see QR codes in our daily life, QR codes save many users' time.

We can also use the python library qrcode to create unique QR codes for websites or profiles.

Installation

pip install qrcode
Copy after login

Code

#import the library
import qrcode
#link to the website
input_data = "https://car-price-prediction-project.herokuapp.com/"
#Creating object
#version: defines size of image from integer(1 to 40), box_size = size of each box in pixels, border = thickness of the border.
qr = qrcode.QRCode(version=1,box_size=10,border=5)
#add_date :pass the input text
qr.add_data(input_data)
#converting into image
qr.make(fit=True)
#specify the foreground and background color for the img
img = qr.make_image(fill='black', back_color='white')
#store the image
img.save('qrcode_img.png')
Copy after login

7. Translation

We live in a multilingual world.

So, in order to understand different languages, we need a language translator.

We can create our own language translator with the help of python library Translator.

Installation

pip install translate
Copy after login

Code

#import the library
from translate import Translator
#specifying the language
translator = Translator(to_lang="Hindi")
#typing the message
translation = translator.translate('Hello!!! Welcome to my class')
#print the translated message
print(translation)
Copy after login

Sometimes programming is so busy that we feel too lazy to open the browser to search for what we want Want the answer.

But with Google’s amazing python library, we only need to write 3 lines of code to search our query, instead of manually opening the browser and searching our query on it.

Installation

pip install google
Copy after login

Code

#import library
from googlesearch import search
#write your query
query = "best course for python"
# displaying 10 results from the search
for i in search(query, tld="co.in", num=10, stop=10, pause=2):
print(i)
#you will notice the 10 search results(website links) in the output.
Copy after login

9. Extract audio

In some cases we have mp4 files but we only need the audio in it , such as making a video using the audio of another video.

We tried hard enough to get the same audio files but we failed.

This problem can be easily solved using the python library moviepy.

Installation

pip install moviepy
Copy after login
Copy after login

Code

#import library
import moviepy.editor as mp
#specify the mp4 file here(mention the file path if it is in different directory)
clip = mp.VideoFileClip('video.mp4')
#specify the name for mp3 extracted
clip.audio.write_audiofile('Audio.mp3')
#you will notice mp3 file will be created at the specified location.
Copy after login

I often deal with various links, and long URLs make my thoughts confusing. Unbearable!

So, there are various short link generation tools.

However, most of them are troublesome to use.

We can create our own short link generator with the help of the python library pyshorteners.

Installation

pip install pyshorteners
Copy after login

Code

#import library
import pyshorteners
#creating object
s=pyshorteners.Shortener()
#type the url
url = "type the youtube link here"
#print the shortend url
print(s.tinyurl.short(url))
Copy after login

After reading this, you will find that in addition to completing the development of machine learning, data analysis and other projects involved in the work, Python can also complete a lot Very interesting and can greatly improve work efficiency.

This article is just to introduce some ideas, I hope you can find more interesting ways to play Python!

The above is the detailed content of These Python operations are amazing and practical!. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Python vs. JavaScript: The Learning Curve and Ease of Use Python vs. JavaScript: The Learning Curve and Ease of Use Apr 16, 2025 am 12:12 AM

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Can vs code run in Windows 8 Can vs code run in Windows 8 Apr 15, 2025 pm 07:24 PM

VS Code can run on Windows 8, but the experience may not be great. First make sure the system has been updated to the latest patch, then download the VS Code installation package that matches the system architecture and install it as prompted. After installation, be aware that some extensions may be incompatible with Windows 8 and need to look for alternative extensions or use newer Windows systems in a virtual machine. Install the necessary extensions to check whether they work properly. Although VS Code is feasible on Windows 8, it is recommended to upgrade to a newer Windows system for a better development experience and security.

Can visual studio code be used in python Can visual studio code be used in python Apr 15, 2025 pm 08:18 PM

VS Code can be used to write Python and provides many features that make it an ideal tool for developing Python applications. It allows users to: install Python extensions to get functions such as code completion, syntax highlighting, and debugging. Use the debugger to track code step by step, find and fix errors. Integrate Git for version control. Use code formatting tools to maintain code consistency. Use the Linting tool to spot potential problems ahead of time.

How to run python with notepad How to run python with notepad Apr 16, 2025 pm 07:33 PM

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Is the vscode extension malicious? Is the vscode extension malicious? Apr 15, 2025 pm 07:57 PM

VS Code extensions pose malicious risks, such as hiding malicious code, exploiting vulnerabilities, and masturbating as legitimate extensions. Methods to identify malicious extensions include: checking publishers, reading comments, checking code, and installing with caution. Security measures also include: security awareness, good habits, regular updates and antivirus software.

See all articles