当前位置:网站首页>Learn this trick and never be afraid to let the code collapse by mistake
Learn this trick and never be afraid to let the code collapse by mistake
2022-07-28 02:26:00 【51CTO】
Reading guide
I learned a very interesting move today , Ride the hot iron to share a wave !
More specifically, it is about python Application of exception handling , Realize a function that you can be forgiven for wrong hand input , It's very easy to use and interesting >_<

One 、 Exception and exception handling
In order to have a clearer understanding of what needs to be done next , We need to understand a few concepts first .
First of all , What is an anomaly . An exception is an event , This event occurs during program execution , It affects the normal execution of the program .
An inappropriate metaphor is , When you are picking up girls , Suddenly a silly Eagle came and said you had bad breath , Always fart , It directly makes you unable to pick up girls normally .
second , What exception handling , In order to solve when an exception occurs , We don't want our program to hang up , And some operations .
And exception handling is similar to when you know this unlucky guy is coming , There must be no good words , You predicted in advance that it would happen , Backhand is to slap him , Then let him talk well , In the end, things are going in a good direction .
Two 、 Small application of exception handling
We often encounter, for example, the need to enter a password , When you enter the wrong password , You don't want to quit the system , Instead, re-enter the password ; Or to read a picture , But sometimes the hand hits the wrong path by mistake , You don't want the whole code to run again , In order for the code to recognize your mistakes and allow you to re-enter , Until you finally enter the path correctly .
In this case , Wrong address , The code stops directly , It's not what we want
How can we solve it ?
Ideas :
(1) Find out what may go wrong , Make detection and judgment ;
(2) When the input is correct , Go directly to the next step ;
(3) When the input is wrong , Re execution , Until it's right .
Complete code : https://github.com/DWCTOD/AI_study/blob/master/06-yichangchuli
3、 ... and 、 Effect display
Use the screen recording software provided by the system to operate it again , Let everyone see more clearly :

It's hard , I don't know why there is a problem with the displayed picture , This screen recording software is poisonous , It's OK to see it on your computer !!! Study it later .
Here is just a simple demonstration of an interesting function , For exception handling , I didn't learn deeply enough , If you get a chance later , Continue to study !


边栏推荐
- What is eplato cast by Plato farm on elephant swap?
- 微信小程序实现动态横向步骤条的两种方式
- Data output - dynamic drawing
- Alipay applet authorization / obtaining user information
- Which database is the fastest to query data only?
- 【HCIP】路由策略、策略路由
- Common video resolution
- 学会这招再也不怕手误让代码崩掉
- They are all talking about Devops. Do you really understand it?
- 产品解读丨MeterSphere UI测试模块的设计与分布式扩展
猜你喜欢

【ROS进阶篇】第十讲 基于Gazebo的URDF集成仿真流程及实例

Appium click operation sorting
![This operation may not be worth money, but it is worth learning | [batch cutting of pictures]](/img/e8/a34e471b0089f8085b140c74b5c01f.jpg)
This operation may not be worth money, but it is worth learning | [batch cutting of pictures]

Record a production deadlock

新零售业态下,零售电商RPA助力重塑增长

Flex development web page instance web side
![[database data recovery] data recovery case of insufficient disk space of SQL Server database](/img/0e/908db40e1e8b7dd62e12558c1c6dc4.png)
[database data recovery] data recovery case of insufficient disk space of SQL Server database

使用BigDecimal类型应该避免哪些问题?(荣耀典藏版)

MySQL是如何利用索引的(荣耀典藏版)

小米网站主页面大模块——小模块+导航(浮动案例)
随机推荐
[机缘参悟-53]:阳谋立身,阴谋防身
小程序毕设作品之微信校园维修报修小程序毕业设计成品(4)开题报告
54: Chapter 5: develop admin management services: 7: face warehousing process; Face login process; The browser turns on the video debugging mode (so that the camera can also be turned on in the case o
OBS键盘插件自定义diy
[website construction] update SSL certificate with acme.sh: change zerossl to letsencrypt
In practical work, how do I use postman for interface testing?
【HCIP】BGP 基础
MySQL 中的 INSERT 是怎么加锁的?(荣耀典藏版)
Shell regular and metacharacters
小米网站主页面大模块——小模块+导航(浮动案例)
Aike AI frontier promotion (7.14)
Implementation of mongodb/mongotemplate.upsert batch inserting update data
[Yugong series] use of tabby integrated terminal in July 2022
53: Chapter 5: develop admin management service: 6: develop [admin administrator exit login, interface]; (one point: when we want to modify a value with a certain coding method, the new value should b
探究flex-basis
Execute add migration migration and report build failed
11 Django basics database operation
Promise从入门到精通(第4章 async 和 await)
Sample imbalance - entry 0
Wechat applet pictures are scaled according to the screen scale