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, ""))
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
Code
from moviepy.editor import VideoFileClip clip = VideoFileClip("video_file.mp4") # Enter your video's path clip.write_gif("gif_file.gif", fps = 10)
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
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)
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
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()
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
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")
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
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')
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
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)
8. Google Search
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
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.
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
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.
10. Generate short links
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
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))
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



MySQL has a free community version and a paid enterprise version. The community version can be used and modified for free, but the support is limited and is suitable for applications with low stability requirements and strong technical capabilities. The Enterprise Edition provides comprehensive commercial support for applications that require a stable, reliable, high-performance database and willing to pay for support. Factors considered when choosing a version include application criticality, budgeting, and technical skills. There is no perfect option, only the most suitable option, and you need to choose carefully according to the specific situation.

HadiDB: A lightweight, high-level scalable Python database HadiDB (hadidb) is a lightweight database written in Python, with a high level of scalability. Install HadiDB using pip installation: pipinstallhadidb User Management Create user: createuser() method to create a new user. The authentication() method authenticates the user's identity. fromhadidb.operationimportuseruser_obj=user("admin","admin")user_obj.

MySQL Workbench can connect to MariaDB, provided that the configuration is correct. First select "MariaDB" as the connector type. In the connection configuration, set HOST, PORT, USER, PASSWORD, and DATABASE correctly. When testing the connection, check that the MariaDB service is started, whether the username and password are correct, whether the port number is correct, whether the firewall allows connections, and whether the database exists. In advanced usage, use connection pooling technology to optimize performance. Common errors include insufficient permissions, network connection problems, etc. When debugging errors, carefully analyze error information and use debugging tools. Optimizing network configuration can improve performance

It is impossible to view MongoDB password directly through Navicat because it is stored as hash values. How to retrieve lost passwords: 1. Reset passwords; 2. Check configuration files (may contain hash values); 3. Check codes (may hardcode passwords).

The MySQL connection may be due to the following reasons: MySQL service is not started, the firewall intercepts the connection, the port number is incorrect, the user name or password is incorrect, the listening address in my.cnf is improperly configured, etc. The troubleshooting steps include: 1. Check whether the MySQL service is running; 2. Adjust the firewall settings to allow MySQL to listen to port 3306; 3. Confirm that the port number is consistent with the actual port number; 4. Check whether the user name and password are correct; 5. Make sure the bind-address settings in my.cnf are correct.

MySQL can run without network connections for basic data storage and management. However, network connection is required for interaction with other systems, remote access, or using advanced features such as replication and clustering. Additionally, security measures (such as firewalls), performance optimization (choose the right network connection), and data backup are critical to connecting to the Internet.

MySQL database performance optimization guide In resource-intensive applications, MySQL database plays a crucial role and is responsible for managing massive transactions. However, as the scale of application expands, database performance bottlenecks often become a constraint. This article will explore a series of effective MySQL performance optimization strategies to ensure that your application remains efficient and responsive under high loads. We will combine actual cases to explain in-depth key technologies such as indexing, query optimization, database design and caching. 1. Database architecture design and optimized database architecture is the cornerstone of MySQL performance optimization. Here are some core principles: Selecting the right data type and selecting the smallest data type that meets the needs can not only save storage space, but also improve data processing speed.

As a data professional, you need to process large amounts of data from various sources. This can pose challenges to data management and analysis. Fortunately, two AWS services can help: AWS Glue and Amazon Athena.
