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!

Curses首先出场的是 Curses[1]。CurseCurses 是一个能提供基于文本终端窗口功能的动态库,它可以: 使用整个屏幕 创建和管理一个窗口 使用 8 种不同的彩色 为程序提供鼠标支持 使用键盘上的功能键Curses 可以在任何遵循 ANSI/POSIX 标准的 Unix/Linux 系统上运行。Windows 上也可以运行,不过需要额外安装 windows-curses 库:pip install windows-curses 上面图片,就是一哥们用 Curses 写的 俄罗斯

相比大家都听过自动化生产线、自动化办公等词汇,在没有人工干预的情况下,机器可以自己完成各项任务,这大大提升了工作效率。编程世界里有各种各样的自动化脚本,来完成不同的任务。尤其Python非常适合编写自动化脚本,因为它语法简洁易懂,而且有丰富的第三方工具库。这次我们使用Python来实现几个自动化场景,或许可以用到你的工作中。1、自动化阅读网页新闻这个脚本能够实现从网页中抓取文本,然后自动化语音朗读,当你想听新闻的时候,这是个不错的选择。代码分为两大部分,第一通过爬虫抓取网页文本呢,第二通过阅读工

糟透了我承认我不是一个爱整理桌面的人,因为我觉得乱糟糟的桌面,反而容易找到文件。哈哈,可是最近桌面实在是太乱了,自己都看不下去了,几乎占满了整个屏幕。虽然一键整理桌面的软件很多,但是对于其他路径下的文件,我同样需要整理,于是我想到使用Python,完成这个需求。效果展示我一共为将文件分为9个大类,分别是图片、视频、音频、文档、压缩文件、常用格式、程序脚本、可执行程序和字体文件。# 不同文件组成的嵌套字典 file_dict = { '图片': ['jpg','png','gif','webp

长期以来,Python 社区一直在讨论如何使 Python 成为网页浏览器中流行的编程语言。然而网络浏览器实际上只支持一种编程语言:JavaScript。随着网络技术的发展,我们已经把越来越多的程序应用在网络上,如游戏、数据科学可视化以及音频和视频编辑软件。这意味着我们已经把繁重的计算带到了网络上——这并不是JavaScript的设计初衷。所有这些挑战提出了对新编程语言的需求,这种语言可以提供快速、可移植、紧凑和安全的代码执行。因此,主要的浏览器供应商致力于实现这个想法,并在2017年向世界推出

2017 年 Transformer 横空出世,由谷歌在论文《Attention is all you need》中引入。这篇论文抛弃了以往深度学习任务里面使用到的 CNN 和 RNN。这一开创性的研究颠覆了以往序列建模和 RNN 划等号的思路,如今被广泛用于 NLP。大热的 GPT、BERT 等都是基于 Transformer 构建的。Transformer 自推出以来,研究者已经提出了许多变体。但大家对 Transformer 的描述似乎都是以口头形式、图形解释等方式介绍该架构。关于 Tra

首先要说,聚类属于机器学习的无监督学习,而且也分很多种方法,比如大家熟知的有K-means。层次聚类也是聚类中的一种,也很常用。下面我先简单回顾一下K-means的基本原理,然后慢慢引出层次聚类的定义和分层步骤,这样更有助于大家理解。层次聚类和K-means有什么不同?K-means 工作原理可以简要概述为: 决定簇数(k) 从数据中随机选取 k 个点作为质心 将所有点分配到最近的聚类质心 计算新形成的簇的质心 重复步骤 3 和 4这是一个迭代过程,直到新形成的簇的质心不变,或者达到最大迭代次数

大家好,我是J哥。这个没有点数学基础是很难算出来的。但是我们有了计算机就不一样了,依靠计算机极快速的运算速度,我们利用微分的思想,加上一点简单的三角学知识,就可以实现它。好,话不多说,我们来看看它的算法原理,看图:由于待会要用pygame演示,它的坐标系是y轴向下,所以这里我们也用y向下的坐标系。算法总的思想就是根据上图,把时间t分割成足够小的片段(比如1/1000,这个时间片越小越精确),每一个片段分别构造如上三角形,计算出导弹下一个时间片走的方向(即∠a)和走的路程(即vt=|AC|),这时

Python这门语言很适合用来写些实用的小脚本,跑个自动化、爬虫、算法什么的,非常方便。这也是很多人学习Python的乐趣所在,可能只需要花个礼拜入门语法,就能用第三方库去解决实际问题。我在Github上就看到过不少Python代码的项目,几十行代码就能实现一个场景功能,非常实用。比方说仓库Python-master里就有很多不错的实用Python脚本,举几个简单例子:1. 创建二维码import pyqrcode import png from pyqrcode import QRCode


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

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
