日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python这些操作,逆天且实用!

發(fā)布時(shí)間:2024/9/16 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python这些操作,逆天且实用! 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

是不是經(jīng)常遇到這種窘境?當(dāng)親戚朋友來家做客,問起WiFi密碼,然后翻箱倒柜、問了一圈也找不到。

今天,給大家介紹Python一些鮮為人知的操作。

這些操作,并非是炫技,而是真的實(shí)用!

1. 顯示W(wǎng)iFi密碼

我們經(jīng)常忘記wifi的密碼,可是每當(dāng)家里來了親戚朋友問起WiFi密碼,卻又無從下手。

這里有一個(gè)技巧,我們可以列出所有的設(shè)備和它們的密碼。

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. 視頻轉(zhuǎn)GIF

近年來,GIF出現(xiàn)了熱潮。大多數(shù)流行的社交媒體平臺(tái),都為用戶提供了各種GIF,以更有意義和更容易理解的方式表達(dá)他們的想法。

很多同學(xué)為了將視頻轉(zhuǎn)成GIF可謂是煞費(fèi)苦心,而且在這個(gè)過程中踩了不少坑。

而使用Python,簡(jiǎn)短的幾行代碼即可解決!

安裝

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. 桌面提醒

當(dāng)我們?cè)谧鲰?xiàng)目或其他事情的時(shí)候,我們可能會(huì)忘記某些重要的事情,我們可以通過在系統(tǒng)上看到一個(gè)簡(jiǎn)單的通知來記住這些。

在python的幫助下,我們可以創(chuàng)建個(gè)性化的通知,并可以將其安排在特定的時(shí)間。

安裝

pip install win10toast, schedule

代碼

import win10toast toaster = win10toast.ToastNotifier() import schedule import time def job():toaster.show_toast('提醒', "到吃飯時(shí)間了!", 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. 自定義快捷鍵

有時(shí),我們?cè)诠ぷ髦行枰l繁地輸入一些單詞。如果我們能使我們的鍵盤自動(dòng)化,只用縮寫就能寫出這些經(jīng)常使用的單詞,這不是很有趣嗎?

沒錯(cuò),我們可以用Python使之成為可能。

安裝

pip install keyboard

代碼

import keyboard #press sb and space immediately(otherwise the trick wont work) keyboard.add_abbreviation('ex', '我是一條測(cè)試數(shù)據(jù)!') #provide abbreviation and the original word here # Block forever, like `while True`. keyboard.wait()

然后,在任何位置輸入ex加空格就可以快速補(bǔ)全對(duì)應(yīng)的語句!

5. 文本轉(zhuǎn)PDF

我們都知道,部分筆記和在線可用的書籍都是以pdf的形式存在。

這是因?yàn)閜df可以以同樣的方式存儲(chǔ)內(nèi)容,而不用考慮平臺(tái)或設(shè)備。

因此,如果我們有文本文件,我們可以在python庫(kù)fpdf的幫助下將它們轉(zhuǎn)換成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. 生成二維碼

我們?cè)谌粘I钪薪?jīng)常看到二維碼,QR碼節(jié)省了很多用戶的時(shí)間。

我們也可以用python庫(kù)qrcode為網(wǎng)站或個(gè)人資料創(chuàng)建獨(dú)特的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. 翻譯

我們生活在一個(gè)多語言的世界里。

因此,為了理解不同的語言,我們需要一個(gè)語言翻譯器。

我們可以在python庫(kù)Translator的幫助下創(chuàng)建我們自己的語言翻譯器。

安裝

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搜索

有時(shí)候編程太忙碌,以至于我們覺得懶得打開瀏覽器來搜索我們想要的答案。

但是有了google這個(gè)神奇的python庫(kù),我們只需要寫3行代碼就可以搜索我們的查詢,而不需要手動(dòng)打開瀏覽器并在上面搜索我們的查詢。

安裝

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文件,但我們只需要其中的音頻,比如用另一個(gè)視頻的音頻制作一個(gè)視頻。

我們?yōu)楂@得相同的音頻文件做了足夠的努力,但我們失敗了。

這個(gè)問題用python庫(kù)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. 生成短鏈接

經(jīng)常和各種各樣的鏈接打交道,過長(zhǎng)的URL讓思緒混亂不堪!

于是,就有了各種各樣的短鏈接生成工具。

不過,大多數(shù)使用都比較麻煩。

我們可以在python庫(kù)pyshorteners的幫助下創(chuàng)建我們自己的短鏈接生成器。

安裝

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))

讀到這里,會(huì)發(fā)現(xiàn),Python除了完成工作中涉及到的機(jī)器學(xué)習(xí)、數(shù)據(jù)分析等項(xiàng)目開發(fā),還可以完成很多非常 有趣,且能夠極大提高工作效率的操作。

本文就是拋磚引玉一下,希望大家能夠?qū)ふ业礁嘤腥さ腜ython玩法!

END

推薦閱讀牛逼!Python常用數(shù)據(jù)類型的基本操作(長(zhǎng)文系列第①篇) 牛逼!Python的判斷、循環(huán)和各種表達(dá)式(長(zhǎng)文系列第②篇)牛逼!Python函數(shù)和文件操作(長(zhǎng)文系列第③篇)牛逼!Python錯(cuò)誤、異常和模塊(長(zhǎng)文系列第④篇)

總結(jié)

以上是生活随笔為你收集整理的Python这些操作,逆天且实用!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。