Python advanced project (please let me know if you forward)

User 2966292 2021-02-23 16:46:24
python advanced project let know

Use Python Do audio processing

The most common audio processing tasks in programming include – Load and save audio files , Split and append the audio file to the clip , Create mixed audio files with different data , Control sound level , Apply some filters as well as generate audio adjustments and maybe more .

AudioSegment yes Pydub The parent class in . It plays the role of being able to load , The function of the container for operating and saving audio files . Let's use it python Create our first audio . Replace , We will need a test file , The file can be in any format , for example WAV,MP3 Or any format . ad locum , I'm going to download an audio file , Just like we grab data from the Internet : install Pydub It's like Python Pydub Like all the other modules in , You can also use simple commands –pip install pydub Easy installation .

Load and play AudioSegment yes Pydub The parent class in . It plays the role of being able to load , The function of the container for operating and saving audio files . Let's use it python Create our first audio . Replace , We will need a test file , The file can be in any format , for example WAV,MP3 Or any format . ad locum , I'm going to download an audio file , Just like we grab data from the Internet :

After loading the audio , Now we can perform all kinds of audio processing , Let's start by repeating some of the necessary steps for an audio file :

We just simply repeated the audio above , Now let's divide and mix different levels of audio

Now? , Let's apply filters and invert audio effects , Put everything together , To further develop :

If you want to save an audio file , You can easily operate as shown below :

Synthetic tones ( Due to transcoding problem , Please test yourself )

These processes can be sine waves of any frequency , Square wave or longitudinal wave . We can also perform white noise . In the following example , I'm going to show the sine method , In the form of harmonics for the initial 15 Two intervals produce sinusoidal tuning :

Use Python The digital clock

Let's see how to use Python Create a digital clock GUI Applications . I'll start with the import library :

Now? , Let's define the title and size of the application . Please note that , In the following code , If you want fixed windows and don't want to maximize or minimize output , You can set the height and width of the resizable function to True (1,1), You can set it to False(0 ,0)

Next , I'm going to define the font of time and its color , Border width and background color of digital clock :

Combine all the elements to define the label of the clock application :

Define the main functions of the digital clock . ad locum , I set the label text to real time :

Run and see the output :

Use Python Get desktop notifications

How desktop notification applications work ?

The task to-do list , In this list we have a goal to achieve . And the desktop notification app will keep us informed of different tasks and actions to be taken throughout the day .

Create a desktop notification application , To remind you Take an hour off . Your messages and alerts can be anything you want . You can go to One day , A week or a month List the things you need to do , And the reminder app keeps reminding you of the same things . For this project , You need to install a device called Plyer Of Python library , The library is used to access the hardware components of the system . Use pip Command can easily install the library pip install pyler..

Let's see how to write Python Program to get desktop notification :

Using mobile phone camera as computer vision

For those who plan to create a computer vision application that will use a smartphone camera as part of the application , Connect your camera with Python Very useful in combination . ad locum , I am Windows 10 Upper use Python. Hopefully it will work for other operating systems as well , But if you use Windows, Please don't worry , Just follow these steps .

stay Python The process of using a mobile phone camera in a mobile phone :

• First , stay Python Install in OpenCV library ;pip install opencv-python.• Download and install... On your smartphone ip wencam Applications .• install ip wencam After the application , Please make sure your phone and PC Connect to the same network . Run the app on your phone , Then restart the server .• after , Your camera will turn on , The bottom has IP Address . Copy IP Address , Because we need to Python It's used in the code to turn on the phone's camera .


later , A OpenCV window , Then do the rest . To close the window , Just press any key . This is to connect the camera of the phone with Python How to connect to use computer vision applications . If you want to Get some computer vision tutorials , Can be in WeChat official account back office : Computer vision course .

Python Music player

The first is to choose one Python GUI frame , Here I'm going to use two main GUI Module to use Python Create a music player :


Pygame It's for creating video games Python library . To use Python Create a music player , We will use Pygame Sound components . Tkinter Is used to create GUI The library of the application . ad locum , We don't need to use too many functions , Just use Tkinter Of askdirectory() Methods and , The method you see in the code section below is enough . then , We're going to create a play , stop it , Pause and resume and so on , To control the music player . Build some functions , And use Tkinter Create buttons in the interface .

The rest is to combine the above , Use Python Create a music player .

Python Realize the game of life

English mathematician John ·H· conway John H. Conway) The imaginary game of life is a card game , Even the rise and fall of biological organism society , alternate . The rules of the game :

• The game uses a rectangular grid of infinite cells , Each cell is empty or replaced by a creature . Some people say , The occupied cell is still alive , And the empty cell died . The game is played in a certain period of time , Each turn creates a new one based on the division of organisms in the current configuration “ Time ”.• If a unit is alive , And have two or three living neighbors , The unit will remain active in the interconnection .• Living cells that have no living neighbors or only one living neighbor die in isolation in succession .• Biological cells with four or more biological neighbors will die from overpopulation in the process of regeneration .• Dead cells with three living neighbors lead to birth , And survive before and after .


Extract text from video

I'll show you how to use Python Extract text from video . The first step is to download the video . After downloading the video , You need to install two Python library :

SpeechRecognition:pip install SpeechRecognitionmoviepy:pip install moviepy

After installing the above two Python After the library , You can start with coding . This is the complete conversion of video to text Python Program :

Finish the above Python After code , You need to create a text document to store all the text extracted from the video :

Python Create a fixed spin game

Now? , Let's see how to use Python Create a game . I'm going to create a very simple game based on the fidget spinner . The logic of the game is , The number of turns will keep increasing when you press the space bar , And the turning speed will be reduced , And stop when you stop pressing the space bar .

( So you can't upload the video . Please pay attention to my official account CoXie Take you to programming .

Use Python Make spelling corrections

contrary , Real word spelling involves detecting and correcting spelling errors , Sometimes it even leads to real English words ( real ). Spelling correction is usually viewed from two perspectives . Non word spelling check is to detect and correct spelling errors that lead to non words . This may come from a notional error that accidentally produces real words ( Insert , Delete , transposition ) The printing error of , It may also be due to the author's cognitive error in replacing the wrong words .

How to create and use Python Programming language spelling correction procedures :

Wrong word :['Data Scence','Mahine Learnin'] The correct word is :Data Science Machine Learning

Use Python establish Turtle graphics

first , The tortoise is just a physical object , Like a robot that can be placed on a piece of paper and instructed to move . then , The tortoise became a visual display that could touch the screen , Usually replaced with any kind of shape . Even in pure graphic format ,“ Tortoise ” The concept of can also more easily express the action taken , So it represents the function of the program .

The tortoise has a place , Direction ( The direction the tortoise faces ) And a variety of possible states ( Turtles can replace a specific color when they move or leave no trace ) The tortoise module of provides an environment , Where the tortoise moves around on a two-dimensional grid . Line ) And the action ( Rotate left or right ; Move forward or backward ).

Python My Monty · Hall problem

Monty Hall The problem is that :

• There are three doors to the show . Prizes like cars or vacations are behind a door , The other two doors hide worthless prizes , be called Zonk. In most of the discussions on this issue ,Zonk It's all goats .• Competitors choose a door . Let's assume that the participants don't know which gate will hold the prize , So the contestants just make random choices .• Smiling host Monty · Hall opened another door , Always choose the door that shows the goat , And always give competitors the opportunity to change their choice of the remaining unopened doors .• Contestants choose to change the gate or insist on the first choice .

use Python simulation Monty Hall The problem is simple . We're going to write a function , This function uses Python Of rrandom Module to choose the door that hides the price , At the same time, the initial choice and Monty Choose the door that opens ., Then the function will return a Boolean value , Indicates whether the competitor's final choice is the winning weapon :

I hope you like this article about using Python Programming language simulation Monty Hall The article on the question . Feel free to ask your valuable questions in the comments section below .

Use Python Video to audio converter for

Converting video to audio seems like a strange decision , But it may come in handy in certain circumstances . It's most often used to record tracks of video or extract other tracks from videos that you're only aware of sound .

Tic tac toe

In this , I'll show you how to use it Tic Tac Toe GUI and Python The top of the class Python project . The game is very popular , And it's very simple . It's a game for two . In this game , There is one 3×3 A square chessboard .

There are two basic logic to this game : When both players are human , And one is the computer . I'm going to prepare this for two players with Python The game of tic tac toe .

with Python 's calculator

Kivy Is a free open source Python library , Develop highly interactive cross platform applications quickly and easily . Develop alternatives with other mobile devices ( Such as Android Of Java and iOS Of Objective CKivy The proportion , The execution speed of is the same . Besides ,Kivy Has the huge advantage of being able to run on multiple platforms , It's like HTML5 equally . under these circumstances ,Kivy The operation effect of the system is the best , Because it doesn't rely on clumsy browsers , And many of its components use Cython Library in C To realize , So most graphics processing is directly in GPU Run in . We don't need to use anything called file.kv File to build in the calculator , Because calculator is a very simple application .

Image Converter

To establish a relationship with Python Image conversion system for , Graphical user interface , I will use Python Medium Tkinter library , Is to generate GUI The most famous app Python frame . except Tkinter Of , We still need to Python library PIL It represents Python Image library . The code is as follows :

As you can see in the output window , It will work like all other applications installed on your system . You need to choose one first PNG file , Then click the button ,PNG Convert to JPG, Then you just need to select a folder to save the converted image .

Use Python Visual chessboard

In order to use Python Programming languages create checkerboard , I'm going to use two Python library .Matplotlib For visualizing , and NumPy For generating algorithms , This will help us create and visualize the chessboard .

Preliminary and QR Code reader

First, install the following three libraries :Pillow,OpenCV and Pyzbar.Pillow yes PIL An extension of , It represents Python Image library .

OpenCV It's a famous library , Especially when dealing with computer vision tasks . The last library we need is Pyzbar, This is a python library , Can help us read the code and QR code . You can use pip Command to easily install all libraries .

Now? , The next step is to write decoding functions , Most interesting things will happen here . The decoding function will mainly do three things , It can be listed as follows :

• Identify and decode the barcode to be displayed on the camera / QR code .• Added the barcode stored in the recognition file as text / QR The information on the code .• Last , Export stored information as a text document . Let's introduce the library that we installed before we wrote the function :

Now let's see what I'm doing through the functions above :

• First , We decode barcodes or QR Code information . Then arrange a rectangle around it . It can help us see if the machine detects a barcode / Qr code .• secondly , We add text above the rectangle that we have created . The text will display the decoded information .• Third , We export the information into a text document .

Now? , Next is writing for using Python Embedding and QR The main function of code reader . Let's create our main features :

Now? , Let's learn about my work through the main functions above :

• First , We use OpenCV Turn on the computer camera . If you have an external camera , You need to change the value according to the device 0 Change to 1.• secondly , We run a loop to continue the decoding function , Until pressed “ Esc” key . otherwise , The loop will not stop and cause problems .• Third , We start the camera that was turned on in the first step . Then close the application window .OpenCV Complete all work , Just call the method .• Last , We call main Function to trigger the program .

Now? , You can display the code on the camera of your laptop , Easily run the code and scan any barcode and QR code .

Use Python Create audio books

PyPDF2 Allow manipulation of... In memory pdf. This python The library can perform the following tasks :

• Extract information about the document , For example, the title , Author, etc .• Documents are divided by page • Merge documents per page • Crop the page • Merge multiple pages into one • Encryption and decryption PDF file • And more .

I'll use the library to split page by page pdf file , Then read the text on each page , Then send the text to the user Python The next step in the process of creating audio books .

pyttsx3 library , The ability to convert text back to speech . then , We reset pdf Read the text as input into the text to the voice engine :

Now? , The next step in the process is loop processing pdf Every page of the document , Finally, stop pyttsx3 Speaker engine :

Now? , The next step is to save the audio as mp3 file :

from PDF Extract text

from PDF When extracting text from a file , The biggest challenge we face is PDF Files are in different file formats . therefore , First we need to prepare a function , The brakes can turn PDF Multiple formats of the file are converted to the desired format .

Now? , Let's start this mission , To use the Python from PDF Extract text from text . First , We need to import all copies . You need to pdf2image Only then PDF The file is converted to ppm image file .

We also need to manipulate the path to add and rename text files , So we introduce os and sys Replace . The following section calls PIL library , And use pytesseract Import images :

We need to initialize the path and counter of the document , The brakes will be on later pdf Extract function to count the documents in the folder :

We need to go from pdf Delete some unnecessary files from the file , It is estimated that , I'm going to create a new function :

First , I'm going to create a list of pdf Documents and a Docx List of documents , Because these two types are the most commonly used pdf file type :

We can finally start from PDF The text is extracted from the file . This is a pdf_extract function . First , It prints the name of each file from which the text is extracted . Depending on the size of the document , Extracting text may take some time . This print function will help you to view the currently overhauled files :

We can use functions to use Python From all PDF Extract in file :

After running this function , If you want to go to the directory , You will see a name called result1.txt Text file for , It contains all the information from PDF The text extracted from the file

3D graphics

The most basic three-dimensional drawing is made up of (x,y,z) A line or scatter diagram created by a set of triples . Similar to the more common two-dimensional graph , We can use ax.plot3D and ax.scatterd3D Function to create these graphs . Same signature . ad locum , We're going to introduce the Triangular Spiral , And randomly place some points near the line :

Outline 3D products It's like two dimensions `ax.contour`` Like drawing ,ax.contour3D All input data is required to be in the form of two-dimensional regular grid , And evaluate at each point Ž data . ad locum , We're going to show a three-dimensional outline of a three-dimensional sine function :

they The value of the mesh is used to project it onto the specified three-dimensional surface , The 3D form generated by the substitution is very easy to visualize . This is an example of using wireframe :

Adding a color map to the size of the fill can help you perceive the deformation of the surface being visualized :

Image filtering

We'll start with all the libraries and images , To explore image filtering technology in machine learning .

The image above shows that some of the noise has been reduced , But now some of the images didn't appear on the screen before . Let's see if we filter the image to grayscale , Are these markers still present :

Use Python Send email

because python The script will access Gmail Account to send email , So we need to “ Applications that allow security changes ” Set to “ open ”. This will make our python It's easier for programs to access your account . therefore , It is recommended to create a temporary account for this .

To use Python Send email , We need to create one called template.txt Text file for . This text file contains the format of the email body :

then , The next file you should have is CSV file . The file I'm going to use contains the details that need to be placeholders in the template file . It contains the details that should be sent to the recipient . It can be Excel File or CSV file .

Write code CSV When the files and template files are ready , Now it's time to write code to use python Send custom email . Let's start by introducing the necessary modules :

I'm going to create a function to read template.txt file . The following function returns contains template.txt Template object for file content :

Now we need to configure SMTP The server . If you want to share this script with others , It's not a good habit to include the account address and password in the script . Or use input() Allow users to enter passwords when running scripts :

Now? , The final step is to reconstruct the body of the email . For this task , We have to :

Browse CSV file , And for CSV Each line of the file creates a message .

• Use MIMEMultipart() Function to create a message , Replace the details of each line in the template to form the body of the message , Keep it in message variable .• Then configure the parameters , For example, the subject of the message “ from ” and “ To ” Address . take message Variables are attached to the body of the message .• Last , adopt send_message() Function to send a message .

This article is from WeChat official account. - CoXie Take you to programming (Pythoni521) , author :CoXie

The source and reprint of the original text are detailed in the text , If there is any infringement , Please contact the Delete .

Original publication time : 2021-02-06

Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .

本文为[User 2966292]所创,转载请带上原文链接,感谢

  1. Python notes: List
  2. Translation: practical Python Programming 02_ 03_ Formatting
  3. Python中的四种队列(queue)、堆(heap)
  4. Side effects of Python mutable types as default parameters of functions
  5. This is the best Python tutorial I've ever seen: ten minutes to get to know python
  6. 使用python编写量子线路打印的简单项目,并使用Sphinx自动化生成API文档
  7. Python happy enemy: crawler and anti crawler with a solution to give you New Year
  8. 使用python编写量子线路打印的简单项目,并使用Sphinx自动化生成API文档
  9. When writing python, you will encounter the following error: modulenotfounderror: no module named ' email.mime '; 'email' is not a package
  10. Python class call and private and public property method call
  11. Proprietary methods for Python classes
  12. Foundation of Python: number string and list
  13. Foundation of Python: number string and list
  14. Foundation of Python: number string and list
  15. 华为 Python网络自动化
  16. Python Cannot open E:\Python36\Scripts\
  17. Peeping into the future is not a dream, python data analysis is easy to achieve
  18. The practical skills summed up by Alibaba and Huawei Python engineers, only you haven't seen them yet?
  19. Sour! See the Python programmers on the tiktok get the pay slip...
  20. Foundation of Python: number string and list
  21. Python installation tutorial
  22. Python installation tutorial
  23. This article will familiarize you with the transformation process of Python - > Cafe - > om model
  24. Four kinds of queues and heaps in Python
  25. Using Python to write a simple project of quantum circuit printing, and using Sphinx to automatically generate API documents
  26. Using Python to write a simple project of quantum circuit printing, and using Sphinx to automatically generate API documents
  27. Huawei Python Network Automation
  28. Python Cannot open E:\Python36\Scripts\pip-
  29. 找不到Python问题解决
  30. PHP和Python哪个更有市场前景?我学的是PHP
  31. Python problem resolution not found
  32. Which has more market prospects, PHP or Python? I studied PHP
  33. Foundation of Python: number string and list
  34. python 编码问题之终极解决
  35. The ultimate solution to the problem of Python coding
  36. 能取值亦能赋值的Python切片
  37. Python slice with value and value
  38. 能取值亦能赋值的Python切片
  39. Python slice with value and value
  40. python 异常处理
  41. Python exception handling
  42. python 异常处理
  43. Python exception handling
  44. Orca: 基于DolphinDB的分布式pandas接口
  45. Orca: distributed panda interface based on dolphin DB
  46. 5个无聊Python程序,用Python整蛊你的朋友们吧
  47. Five boring Python programs, trick your friends with Python
  48. python进阶训练营
  49. Python advanced training camp
  50. 【免费】0基础也能轻松学的Python训练营来啦,限时抢位中!
  51. [free] Python training camp, which is easy to learn, is here. It's time to grab a place!
  52. 手把手教你把Python应用到实际开发 不再空谈语法
  53. 全面系统Python3.8入门+进阶 (程序员必备第二语言)
  54. Hand in hand to teach you how to apply Python to practical development
  55. Comprehensive system introduction to Python 3.8 + Advanced
  56. Python语言的排序算法有哪些?Python学习班!
  57. Python language sorting algorithm what? Python classes!
  58. Java、JavaScript、C、C++、PHP、Python都是用来开发什么?
  59. 为什么学习Python?什么途径学习Python合适?
  60. What are Java, JavaScript, C, C + +, PHP and python used to develop?