日记大全

日记大全 > 句子大全

Python为什么成为世界上最流行和使用最广泛的语言之一呢

句子大全 2009-03-16 19:27:55
相关推荐

导语

大家好,小可爱们!

Python之所以成为世界上最流行和使用最广泛的语言之一,是因为它的简单性和广泛的可用性。

下面是与Python有关的9件令人惊叹的事情。短代码,巨大的结果!!!

1.显示wifi密码:globWith_WITY_经络:

处理wifi密码并不容易。我们经常忘记wifi的密码。这里有一个技巧,我们可以通过它来登记所有的设备和它们的密码,我们的系统是连接到这个密码的。酷,现在我们可以随意连接和断开到wifi设备,因为我们不需要问密码从wifi所有者一次又一次。

安装

# No need to install any, we use built-in ones

电码

import subprocess #import required librarydata = subprocess.check_output(["netsh", "wlan", "show", "profiles"]).decode("utf-8").split("\n") #store profiles data in "data" variableprofiles = [i.split(":")[1][1:-1] for i in data if "All User Profile" in i] #store the profile by converting them to listfor 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掀起了一股新的热潮。大多数流行的社交媒体平台,如WhatsApp、Instagram和Snapchat为用户提供了各种GIF,让他们以更有意义和更理解的方式表达自己的想法。此外,屏幕共享视频对GIF也是很重要的!在python的帮助下,我们可以用我们的视频创建个性化的GIF。

pip install moviepy

from moviepy.editor import VideoFileClipclip = VideoFileClip("video_file.mp4") # Enter your video"s pathclip.write_gif("gif_file.gif", fps = 10)

3.制作有声读物:耳机:

你对像Hashode博客这样的有声读物的想法感到兴奋吗?谁不会呢?是时候创建你自己的有声读物了。现在你可以简单地把你的书(Pdf)转换成有声书,你可以无止境地听到它。如果你像我一样懒惰,整天看书总是很无聊,那么这个技巧对你来说可能是非常有趣和有用的。

pip install PyPDF2, pyttsx3

import pyttsx3import PyPDF2book = open("mybook.pdf"," rb") # Add pathpdf_reader = PyPDF2.PdfFileReader(book)num_pages = pdf_reader.numPagesplay = pyttsx3.init()print("Playing Audio Book")for num in range(0, num_pages): #iterating through all pages page = pdf_reader.getPage(num) data = page.extractText() #extracting text play.say(data) play.runAndWait()

4.桌面通知:Bell:

当我们在做我们的项目或其他事情时,我们可能会忘记一些重要的事情,我们可以通过在系统上看到一个简单的通知来记住这些事情。在python的帮助下,我们可以创建个性化通知,并将它们安排在特定的时间。在我的情况下,当我专注于我的游戏或什么的时候,我经常忘记休息一下,看远,所以我只是安排通知,它显示在我的屏幕上每小时一次。

pip install win10toast, schedule

import win10toasttoaster = win10toast.ToastNotifier()import scheduleimport timedef job(): toaster.show_toast("Reminder", "See far buddy!", duration = 15)schedule.every().hour.do(job) #scheduling for every hour; you can even change the scheduled time with schedule librarywhile True: schedule.run_pending() time.sleep(1)

5.键盘自动化

有时,我们在某些事情上工作,要求我们经常打一些单词。如果我们可以用键盘自动写那些常用的单词,用缩写来写,难道不是很有趣吗?是的,而且我们可以用蟒蛇来实现它。您可以为它们各自的单词设置不同的缩写。所以,当你用键盘输入这些缩略语时,会自动输入整个单词!

Warning: Be careful! This may make you angry.

pip install keyboard

import keyboard#press sb and space immediately(otherwise the trick wont work)keyboard.add_abbreviation("sb", "I am the buddy!") #provide abbreviation and the original word here# Block forever, like `while True`.keyboard.wait()

如代码所示,按S,B和空间。除非它不起作用..。

6.文本文件至PDF:备注:

我们都观察到,我们的大部分笔记和网上可用的书籍都是以pdf的形式出现的。这是因为pdf可以以相同的方式存储内容,而不管平台或设备如何。因此,如果我们有文本文件,我们可以在python库的帮助下将它们转换为PDF文件。

fpdf。让我们看看我们怎么能做到这一点。

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

7.素描图像:照相机:

我们大多数人都喜欢黑白素描。但事实是,创造一个人的脸素描是一项耗时和熟练的任务。但是使用Python,我们只需2分钟就可以完成这个任务。想象不是很酷吗?让我们看看如何用几行代码就可以做到这一点。我们需要安装一个开放的cv库,以处理图像文件。

pip install opencv-python

import cv2image = cv2.imread("profile.jpg") #Import the imagegrey_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) #Add grey filter.invert = cv2.bitwise_not(grey_img) #Add inverted filter.blur = cv2.GaussianBlur(invert,(21,21),0) #Add Blur effectinvertedblur = cv2.bitwise_not(blur)sketch = cv2.divide(grey_img, invertedblur, scale = 256.0)cv2.imwrite("profile_sketch.png", sketch) #Export the sketch image

8.截图

截图对于快速浏览一些东西是很重要的。我们常常对安装哪个软件来截屏感到困惑,因为所有的键盘或操作系统都不支持快速屏幕截图功能。我们可以使用python库来完成这个任务。

pyautogui

.

pip install pyautogui

from time import sleepimport pyautogui#delay the screenshot time by 10 sec, so that you can go the desired page you want the screenshotsleep(10)myScreenshot = pyautogui.screenshot()#provide the path to get the screenshot savedmyScreenshot.save(r"screenshot.png")

9.鼠标自动化

我们都很熟悉这样一个事实:我们的笔记本电脑/台式机在特定的时间段后会自动进入睡眠模式。但这件事有时会给我们带来麻烦,当我们想远离系统,但仍然希望屏幕打开。这可以通过使鼠标自动化来完成,这样屏幕上的光标就可以重复移动几秒钟。这样,我们的系统可以在一个无限的时间内,它不会失去你的焦点!

import pyautoguiimport timepyautogui.FAILSAFE = Falsewhile True: time.sleep(15) for i in range(0,100): pyautogui.moveTo(0,i*5) for i in range(0,3): pyautogui.press("shift")

总结

现在就这样!所以,请在你死前试一试:喜乐::喜乐:。很快就会注意到,这些简短的程序可以产生巨大的效果。保持安全,保持快乐!!!!

源码基地:#私信小编06即可 #记得点赞、评论、关注 三连哦~

阅读剩余内容
网友评论
相关内容
拓展阅读
最近更新