震惊世人的10个Python黑科技,你知道几个?
Python以其大量的預定義庫而聞名,這節省了我們很多時間。在本文中,我們將通過一些稀有卻很酷的庫學習一些驚人的python hack。本文的主要目的是借助python學習(或自動化)一些基本知識。因此,讓我們開始吧。
老規矩,需要打包好的軟件關注小編,QQ群:721195303領取。
1.下載YouTube視頻
我們所有人都在YouTube上看到了一些有用的內容,無論是出于教育目的還是出于娛樂目的。該平臺不向我們收費,可以免費觀看無限多的視頻。唯一的問題出現在我們將來要下載這些視頻時。這是一個很酷的python庫“ pytube”,它支持下載。
要安裝庫:
pip安裝pytube
代碼:?
#import the library from pytube import YouTube #ask user to type in the link link = input("Enter the link of youtube video: ") #creating an object yt = YouTube(link) #to get the highest resolution ys = yt.streams.get_highest_resolution() #show the message until downloading print("Downloading...") #specifying the location for this video ys.download("Downloads\python") #show the message when download is completed print("Download completed!!")2.自動化Whatsapp消息
毫無疑問,Whatsapp已成為Android用戶最默認的應用程序。這個應用程序使我們可以在世界任何角落的任何地方發送消息。除了其所有令人驚奇的功能之外,在特定時間安排我們的消息將是最酷的事情。這可以通過python庫“ pywhatkit”來完成
要安裝庫:
pip安裝pywhatkit
代碼:
#you should be logged in with whatsapp web in your default browser. #import the library import pywhatkit #pywhatkit.sendwhatmsg(reciever's number, message, hour(scheduled) in 24 hr format, minute(scheduled) ) pywhatkit.sendwhatmsg('+91 0000000000','hye, this is automated message',14,22) #message will be sent on sender's number at the scheduled time that is (2:22 pm)3.使用Python的Google搜索?
有時,我們對編程的投入如此之大,以至于覺得自己懶得打開瀏覽器并搜索查詢。但是有了神奇的python庫“ google”,我們只需編寫3行代碼即可搜索我們的查詢,而無需手動打開瀏覽器并在其上搜索查詢。?
要安裝庫:
pip安裝谷歌
代碼:
#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.4.下載Instagram帖子和個人資料圖片
我們都在Instagram上遇到了一些很棒的帖子,并希望將它們離線保存在我們的設備上。但是該應用程序提供的帖子可以在線保存,以備日后使用,而不是離線。這可以通過令人驚嘆的python庫“ instaloader”來完成。
要安裝庫:
pip安裝instaloader
代碼:
#to download all the posts of a profile import instaloader #creating object d = instaloader.Instaloader() #sepcifying the profile name profile_Name = 'enter the instagram_handle' #do profile_pic_only = True, to download the profile picture d.download_profile(profile_Name, profile_pic_only = False) #you will notice a folder of this profile's name, under which all the posts will get downloaded5.從視頻文件中提取音頻
在某些情況下,我們擁有mp4文件,但我們只需要其中的音頻即可。我們已經竭盡全力以獲取相同的音頻文件,但失敗了,很不幸,我們決定選擇其他音樂文件。這個問題可以通過python庫“ moviepy”解決,因為我們可以通過該庫從視頻文件中提取音頻。
要安裝庫:
pip安裝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.6. URL縮短器
當必須定期使用長URL時,處理長URL是一項繁瑣的任務。URL縮短器(例如bit.ly和tinyurl)的想法來了。這些服務將URL縮短到50個字符以下。我們可以在python庫“ pyshorteners”的幫助下創建自己的URL縮短器。?
要安裝庫:
pip安裝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))7.圖像到PDF轉換器
有時我們的筆記或文件是照片,因此很難以這種方式進行研究。我們可能遵循錯誤的順序,事情變得令人困惑和煩惱。為了解決這個問題,一個想法是收集所有圖像,然后將它們轉換為pdf文件。這可以通過python庫“ img2pdf”來完成。
要安裝庫:
pip安裝img2pdf
代碼:
#import libraries import os import img2pdf #specify the name for pdf file with open("converted.pdf", "wb") as f:#collect all the images in a single folder and specify its locationf.write(img2pdf.convert([i for i in os.listdir(files\images) if i.endswith(".jpg")]))8.抄襲探測器?
處理內容寫作的最重要因素之一是Pla竊。捆綁在一起時,甚至無法手動檢查文件。這就需要the竊檢測工具。我們還可以借助python庫“ difflib”創建自己的竊檢測器。它可用于檢查設備上兩個或多個文件之間的相似性。
代碼:
#import the required library from difflib import SequenceMatcher#opening two text fileswith open('file_one.txt') as file_1, open('file_two.txt') as file_2: #read the files in another variablesfile1_data = file_1.read() file2_data = file_2.read() #since we have taken two files for detecting plagiarism, we mention two them heresimilarity_ratio = SequenceMatcher(None,file1_data,file2_data).ratio() #print the plagiarsim ratioprint(similarity_ratio)9.語言翻譯器???
我們生活在一個使用多種語言的人的世界中。因此,要了解彼此的語言,我們需要語言翻譯器,因為我們無法學習許多語言。我們可以借助python庫“ Translator”創建自己的語言翻譯器。
要安裝庫:
pip安裝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)10. QR碼生成器
在我們的日常生活中,我們經常看到QR(快速響應)代碼。一個非常快速的示例是支付應用程序,其中的QR碼可節省大量用戶的時間。我們還可以使用python庫“ qrcode”為網站或個人資料創建唯一的QR碼
要安裝庫:
PIP安裝QR碼
代碼:
#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')在這里還是要推薦下我自己建的Python學習群:721195303,群里都是學Python的,如果你想學或者正在學習Python ,歡迎你加入,大家都是軟件開發黨,不定期分享干貨(只有Python軟件開發相關的),包括我自己整理的一份2021最新的Python進階資料和零基礎教學,歡迎進階中和對Python感興趣的小伙伴加入!
總結
以上是生活随笔為你收集整理的震惊世人的10个Python黑科技,你知道几个?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中国最好的电子商务平台,75商务网成功上
- 下一篇: 大叔手记(21):汤姆大叔博客园开博10