目錄
1. 顯示WiFi密碼
2. 影片轉GIF
安裝
程式碼
3. 桌面提醒
4. 自訂快速鍵
5. 文字轉PDF
6. 產生二維碼
7. 翻譯
8. Google搜尋
代碼
9. 提取音頻
10. 產生短連結
首頁 後端開發 Python教學 Python這些操作,逆天且實用!

Python這些操作,逆天且實用!

May 03, 2023 am 09:52 AM
python 程式碼 wifi密碼

Python這些操作,逆天且實用!

Hello, 大家好,我是菜鳥哥。

是不是常常遇到這種窘境?當親友來家作客,問WiFi密碼,然後翻箱倒櫃、問了一圈也找不到。

今天,要跟大家介紹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 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. 影片轉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這些操作,逆天且實用!的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

<🎜>:泡泡膠模擬器無窮大 - 如何獲取和使用皇家鑰匙
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
北端:融合系統,解釋
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora:巫婆樹的耳語 - 如何解鎖抓鉤
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Java教學
1666
14
CakePHP 教程
1425
52
Laravel 教程
1325
25
PHP教程
1273
29
C# 教程
1252
24
PHP和Python:解釋了不同的範例 PHP和Python:解釋了不同的範例 Apr 18, 2025 am 12:26 AM

PHP主要是過程式編程,但也支持面向對象編程(OOP);Python支持多種範式,包括OOP、函數式和過程式編程。 PHP適合web開發,Python適用於多種應用,如數據分析和機器學習。

在PHP和Python之間進行選擇:指南 在PHP和Python之間進行選擇:指南 Apr 18, 2025 am 12:24 AM

PHP適合網頁開發和快速原型開發,Python適用於數據科學和機器學習。 1.PHP用於動態網頁開發,語法簡單,適合快速開發。 2.Python語法簡潔,適用於多領域,庫生態系統強大。

sublime怎麼運行代碼python sublime怎麼運行代碼python Apr 16, 2025 am 08:48 AM

在 Sublime Text 中運行 Python 代碼,需先安裝 Python 插件,再創建 .py 文件並編寫代碼,最後按 Ctrl B 運行代碼,輸出會在控制台中顯示。

PHP和Python:深入了解他們的歷史 PHP和Python:深入了解他們的歷史 Apr 18, 2025 am 12:25 AM

PHP起源於1994年,由RasmusLerdorf開發,最初用於跟踪網站訪問者,逐漸演變為服務器端腳本語言,廣泛應用於網頁開發。 Python由GuidovanRossum於1980年代末開發,1991年首次發布,強調代碼可讀性和簡潔性,適用於科學計算、數據分析等領域。

Python vs. JavaScript:學習曲線和易用性 Python vs. JavaScript:學習曲線和易用性 Apr 16, 2025 am 12:12 AM

Python更適合初學者,學習曲線平緩,語法簡潔;JavaScript適合前端開發,學習曲線較陡,語法靈活。 1.Python語法直觀,適用於數據科學和後端開發。 2.JavaScript靈活,廣泛用於前端和服務器端編程。

Golang vs. Python:性能和可伸縮性 Golang vs. Python:性能和可伸縮性 Apr 19, 2025 am 12:18 AM

Golang在性能和可擴展性方面優於Python。 1)Golang的編譯型特性和高效並發模型使其在高並發場景下表現出色。 2)Python作為解釋型語言,執行速度較慢,但通過工具如Cython可優化性能。

vscode在哪寫代碼 vscode在哪寫代碼 Apr 15, 2025 pm 09:54 PM

在 Visual Studio Code(VSCode)中編寫代碼簡單易行,只需安裝 VSCode、創建項目、選擇語言、創建文件、編寫代碼、保存並運行即可。 VSCode 的優點包括跨平台、免費開源、強大功能、擴展豐富,以及輕量快速。

notepad 怎麼運行python notepad 怎麼運行python Apr 16, 2025 pm 07:33 PM

在 Notepad 中運行 Python 代碼需要安裝 Python 可執行文件和 NppExec 插件。安裝 Python 並為其添加 PATH 後,在 NppExec 插件中配置命令為“python”、參數為“{CURRENT_DIRECTORY}{FILE_NAME}”,即可在 Notepad 中通過快捷鍵“F6”運行 Python 代碼。

See all articles