Python这些操作,逆天且实用
1. 显示WiFi密码
我们经常忘记wifi的密码,可是每当家里来了亲戚朋友问起WiFi密码,却又无从下手。
这里有一个技巧,我们可以列出所有的设备和它们的密码。
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 passwordsresults = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n')# storing passwords after converting them to listresults = [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. 视频转GIF
近年来,GIF出现了热潮。大多数流行的社交媒体平台,都为用户提供了各种GIF,以更有意义和更容易理解的方式表达他们的想法。
很多同学为了将视频转成GIF可谓是煞费苦心,而且在这个过程中踩了不少坑。
而使用Python,简短的几行代码即可解决!
安装
pip install moviepy
代码
from moviepy.editor import VideoFileClip
clip = VideoFileClip("video_file.mp4") # Enter your video's path
clip.write_gif("gif_file.gif", fps = 10)
3. 桌面提醒
当我们在做项目或其他事情的时候,我们可能会忘记某些重要的事情,我们可以通过在系统上看到一个简单的通知来记住这些。
在python的帮助下,我们可以创建个性化的通知,并可以将其安排在特定的时间。
安装
pip install win10toast, schedule
代码
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. 自定义快捷键
有时,我们在工作中需要频繁地输入一些单词。如果我们能使我们的键盘自动化,只用缩写就能写出这些经常使用的单词,这不是很有趣吗?
没错,我们可以用Python使之成为可能。
安装
pip install keyboard
代码
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()
然后,在任何位置输入ex加空格就可以快速补全对应的语句!
5. 文本转PDF
我们都知道,部分笔记和在线可用的书籍都是以pdf的形式存在。
这是因为pdf可以以同样的方式存储内容,而不用考虑平台或设备。
因此,如果我们有文本文件,我们可以在python库fpdf的帮助下将它们转换成PDF文件。
安装
pip install fpdf
代码
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. 生成二维码
我们在日常生活中经常看到二维码,QR码节省了很多用户的时间。
我们也可以用python库qrcode为网站或个人资料创建独特的QR码。
安装
pip install qrcode
代码
#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. 翻译
我们生活在一个多语言的世界里。
因此,为了理解不同的语言,我们需要一个语言翻译器。
我们可以在python库Translator的帮助下创建我们自己的语言翻译器。
安装
pip install translate
代码
#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搜索
有时候编程太忙碌,以至于我们觉得懒得打开浏览器来搜索我们想要的答案。
但是有了google这个神奇的python库,我们只需要写3行代码就可以搜索我们的查询,而不需要手动打开浏览器并在上面搜索我们的查询。
安装
pip install google
代码
#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. 提取音频
在某些情况下,我们有mp4文件,但我们只需要其中的音频,比如用另一个视频的音频制作一个视频。
我们为获得相同的音频文件做了足够的努力,但我们失败了。
这个问题用python库moviepy可以轻而易举的解决。
安装
pip install moviepy
代码
#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. 生成短链接
经常和各种各样的链接打交道,过长的URL让思绪混乱不堪!
于是,就有了各种各样的短链接生成工具。
不过,大多数使用都比较麻烦。
我们可以在python库pyshorteners的帮助下创建我们自己的短链接生成器。
安装
pip install pyshorteners
代码
#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))
读到这里,会发现,Python除了完成工作中涉及到的机器学习、数据分析等项目开发,还可以完成很多非常 有趣,且能够极大提高工作效率的操作。
本文就是抛砖引玉一下,希望大家能够寻找到更多有趣的Python玩法!
1. 显示WiFi密码
我们经常忘记wifi的密码,可是每当家里来了亲戚朋友问起WiFi密码,却又无从下手。
这里有一个技巧,我们可以列出所有的设备和它们的密码。
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 passwordsresults = subprocess.check_output(['netsh', 'wlan', 'show', 'profile', i, 'key=clear']).decode('utf-8').split('\n')# storing passwords after converting them to listresults = [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. 视频转GIF
近年来,GIF出现了热潮。大多数流行的社交媒体平台,都为用户提供了各种GIF,以更有意义和更容易理解的方式表达他们的想法。
很多同学为了将视频转成GIF可谓是煞费苦心,而且在这个过程中踩了不少坑。
而使用Python,简短的几行代码即可解决!
安装
pip install moviepy
代码
from moviepy.editor import VideoFileClip
clip = VideoFileClip("video_file.mp4") # Enter your video's path
clip.write_gif("gif_file.gif", fps = 10)
3. 桌面提醒
当我们在做项目或其他事情的时候,我们可能会忘记某些重要的事情,我们可以通过在系统上看到一个简单的通知来记住这些。
在python的帮助下,我们可以创建个性化的通知,并可以将其安排在特定的时间。
安装
pip install win10toast, schedule
代码
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. 自定义快捷键
有时,我们在工作中需要频繁地输入一些单词。如果我们能使我们的键盘自动化,只用缩写就能写出这些经常使用的单词,这不是很有趣吗?
没错,我们可以用Python使之成为可能。
安装
pip install keyboard
代码
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()
然后,在任何位置输入ex加空格就可以快速补全对应的语句!
5. 文本转PDF
我们都知道,部分笔记和在线可用的书籍都是以pdf的形式存在。
这是因为pdf可以以同样的方式存储内容,而不用考虑平台或设备。
因此,如果我们有文本文件,我们可以在python库fpdf的帮助下将它们转换成PDF文件。
安装
pip install fpdf
代码
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. 生成二维码
我们在日常生活中经常看到二维码,QR码节省了很多用户的时间。
我们也可以用python库qrcode为网站或个人资料创建独特的QR码。
安装
pip install qrcode
代码
#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. 翻译
我们生活在一个多语言的世界里。
因此,为了理解不同的语言,我们需要一个语言翻译器。
我们可以在python库Translator的帮助下创建我们自己的语言翻译器。
安装
pip install translate
代码
#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搜索
有时候编程太忙碌,以至于我们觉得懒得打开浏览器来搜索我们想要的答案。
但是有了google这个神奇的python库,我们只需要写3行代码就可以搜索我们的查询,而不需要手动打开浏览器并在上面搜索我们的查询。
安装
pip install google
代码
#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. 提取音频
在某些情况下,我们有mp4文件,但我们只需要其中的音频,比如用另一个视频的音频制作一个视频。
我们为获得相同的音频文件做了足够的努力,但我们失败了。
这个问题用python库moviepy可以轻而易举的解决。
安装
pip install moviepy
代码
#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. 生成短链接
经常和各种各样的链接打交道,过长的URL让思绪混乱不堪!
于是,就有了各种各样的短链接生成工具。
不过,大多数使用都比较麻烦。
我们可以在python库pyshorteners的帮助下创建我们自己的短链接生成器。
安装
pip install pyshorteners
代码
#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))
读到这里,会发现,Python除了完成工作中涉及到的机器学习、数据分析等项目开发,还可以完成很多非常 有趣,且能够极大提高工作效率的操作。
本文就是抛砖引玉一下,希望大家能够寻找到更多有趣的Python玩法!
在这里还是要推荐下我自己建的Python学习Q群:831804576,群里都是学Python的,如果你想学或者正在学习Python ,欢迎你加入,大家都是软件开发党,不定期分享干货(只有Python软件开发相关的),
包括我自己整理的一份2021最新的Python进阶资料和零基础教学,欢迎进阶中和对Python感兴趣的小伙伴加入!
Python这些操作,逆天且实用相关推荐
- 初学Python——文件操作第二篇
前言:为什么需要第二篇文件操作?因为第一篇的知识根本不足以支撑基本的需求.下面来一一分析. 一.Python文件操作的特点 首先来类比一下,作为高级编程语言的始祖,C语言如何对文件进行操作? 字符(串 ...
- 【Tools】python环境操作笔记
python环境操作笔记 1.安装Python虚拟环境 2.python pip 添加清华镜像 3.Ubuntu卸载python后出现系统崩溃以及各种问题的解决方法 4.Python下关于 tkint ...
- Python处理视频文件的实用姿势
Python处理视频文件的实用姿势 感觉这辈子,最深情绵长的注视,都给了手机. 视频是目前最热门的领域之一. 各平台争先推出便捷工具,自带滤镜和玩法,普通人也能轻松制作精美视频. 也有不少团队实现了批 ...
- Python处理音频文件的实用姿势
Python处理音频文件的实用姿势 每天叫醒我的不是理想,是楼下广场舞的音乐. 音乐是人类的通用语言,不分国界不分种族. 抖音短视频爆火的关键因素之一,就是普通人也能便捷地使用BGM表达自我. 从感性 ...
- python读写hdfs文件的实用解决方案
大家好,我是爱编程的喵喵.双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中.从事机器学习以及相关的前后端开发工作.曾在阿里云.科大讯飞.CCF等比赛获得多次Top名次.现 ...
- 100天精通Python丨办公效率篇 —— 11、Python自动化操作 Email(发送邮件、收邮件、邮箱客户端)
文章目录 一.通过SMTP发送电子邮件 1.1 定义邮件正文 1.2 发送邮件 二.收取电子邮件 2.1 配置账户信息 2.2 连接邮箱服务器 2.3 搜索返回消息ID 2.4 读取邮件 三.使用邮件 ...
- python excel 打印文档_教你如何用Python轻轻松松操作Excel、Word、CSV,一文就够了,赶紧码住!!!...
原标题:教你如何用Python轻轻松松操作Excel.Word.CSV,一文就够了,赶紧码住!!! 作者:奈何缘浅wyj Python 操作 Excel 常用工具 数据处理是 Python 的一大应用 ...
- OpenCV和Python动手操作计算机视觉学习教程
使用OpenCV和Python进行实际操作 面向初学者的OpenCV Python动手操作计算机视觉 你会学到: NumPy基础知识 基于OpenCV的人脸检测 使用OpenCV在图像和视频上绘制形状 ...
- python字典操作添加_Python字典常见操作实例小结【定义、添加、删除、遍历】
本文实例总结了python字典常见操作.分享给大家供大家参考,具体如下: 简单的字典: 字典就是键值对key-value组合. #字典 键值对组合 alien_0 ={'color':'green', ...
- python中年大叔学编程_中年大叔学编程-Python简单操作文件
原标题:中年大叔学编程-Python简单操作文件 在计算机中,经常打交道的就是各种文档,用得比较多的软件就是office和记事本来操作文件,那么我们试试用Python来简单读写文件. Open函数的用 ...
最新文章
- linux烧录,新人求教,怎么烧录Linux系统到一个小芯片上?
- Jsp登录后数据采集---奇怪的Apache服务器
- Android设备的网络抓包
- linux中的读目录,在linux中读取目录内容
- boost::put_get_helper用法的测试程序
- android 仿快递步骤_Android开发-类似物流快递进度效果
- python线程,进程,队列和缓存
- java安卓开发异步任务_Android笔记4-android之多线程和异步任务
- 恶意混时间你不敢管,却要吓唬全体员工?
- 深度学习文献阅读笔记(6)
- 可做fft分析吗_做数据分析的你,真的会5W2H分析法吗?
- python入门教程
- oracle imp 多用户,用imp把一个用户的架构下的数据导入到另一个用户下的问题
- Excel AES加密
- 图片太多怎么办?教你怎么批量压缩图片大小
- 笔记 09-集合(HashSet HashMap TreeMap) 练习
- mysql eav_mysql – 如何使此eav查询生成水平结果
- 机械转嵌入式开发需要学什么东西?嵌入式软件工程师学习路线
- ECharts3D环型图,设置某一部分弧度的高度
- CentOS 7 搭建 docker+vulhub(漏洞测试靶场)
热门文章
- 【BZOJ1269/1507】[AHOI2006]文本编辑器editor Splay
- 《可复制的领导力》学习总结
- app上架因为副标题被App Store残忍拒绝!
- 大话拒绝服务攻击:DoS、DDoS、LDoS——“直男、舔狗和渣男”
- ES6标准入门略读笔记
- android opengl 坐标系,Android OpenGL ES从白痴到入门(五):妖艳的着色器
- uniapp实现复制功能
- 第四十七题 UVA437 巴比伦塔 The Tower of Babylon
- python基础五之for和while
- QT之如何添加现有文件