>  기사  >  백엔드 개발  >  이러한 Python 작업은 놀랍고 실용적입니다!

이러한 Python 작업은 놀랍고 실용적입니다!

WBOY
WBOY앞으로
2023-05-03 09:52:06825검색

이러한 Python 작업은 놀랍고 실용적입니다!

안녕하세요 여러분 저는 루키입니다.

이 딜레마에 자주 직면하시나요? 친척이나 친구가 손님으로 집에 오면 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로 변환하는 데 많은 노력을 기울였으며 그 과정에서 많은 함정에 직면했습니다.

파이썬을 사용하면 코드 몇 줄만으로 해결 가능해요!

Installation

pip install moviepy

Code

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

3. Desktop Reminder

우리는 프로젝트나 다른 일을 할 때 몇 가지 중요한 사항을 잊어버릴 수 있습니다. 시스템의 간단한 알림을 보면 이를 기억할 수 있습니다.

파이썬의 도움으로 우리는 개인화된 알림을 만들고 특정 시간에 알림을 예약할 수 있습니다.

Installation

pip install win10toast, schedule

Code

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

code

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

Code

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코드 생성

우리는 일상생활에서 자주 접하는 QR코드로 사용자의 시간을 많이 절약해줍니다.

파이썬 라이브러리 qrcode를 사용하여 웹사이트나 프로필에 대한 고유한 QR 코드를 만들 수도 있습니다.

설치

pip install qrcode

Code

#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. 번역

우리는 다국어 세상에 살고 있습니다.

그래서 다른 언어를 이해하려면 언어 번역가가 필요합니다.

파이썬 라이브러리 번역기의 도움으로 우리만의 언어 번역기를 만들 수 있습니다.

Installation

pip install translate

Code

#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줄의 코드만 작성하면 쿼리를 검색할 수 있습니다.

Installation

pip install google

Code

#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를 사용하여 쉽게 해결할 수 있습니다.

Installation

pip install moviepy

Code

#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이 길면 생각이 헷갈리는데요!

그래서 다양한 짧은 링크 생성 도구가 있습니다.

그러나 대부분은 사용하기가 번거롭습니다.

파이썬 라이브러리 pyshorteners의 도움으로 우리만의 짧은 링크 생성기를 만들 수 있습니다.

Installation

pip install pyshorteners

Code

#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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 51cto.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제