Python tricks: All there is to know about Exceptions

  Рет қаралды 18,665

Sebastiaan Mathôt

Sebastiaan Mathôt

Күн бұрын

Пікірлер: 44
@yoninonasade
@yoninonasade 4 жыл бұрын
one of the most useful videos i have ever seen in KZbin. your are my friend a dame good teacher.
@alphainfinitum3445
@alphainfinitum3445 2 жыл бұрын
This is the one video you want to watch. This topic is particularly very confusing on Cisco Networking Academy. Watching this before heading over there is definitely a good idea. You can tell that this guy is a formidable teacher because he is able to cover all the essentials that you need to start writing and reading code in one short video. Thank you very much mate.
@fabulousfabio8228
@fabulousfabio8228 2 жыл бұрын
I really love the rigorous way in which you explain things. Thanks
@juliannash890
@juliannash890 6 жыл бұрын
As someone learning Python, your videos are fantastic :) Keep them coming!
6 жыл бұрын
+Julian Nash thank you!
@sujataroberts3025
@sujataroberts3025 6 жыл бұрын
I tried to learn this from a few sources before I finally understood from watching this. Thank you!
@talmadhoun
@talmadhoun 6 жыл бұрын
You know your stuff and you explain it very well. You're a great teacher. Thank you!
@lexinexiai
@lexinexiai 3 жыл бұрын
Great content, rare content
@fuanka1724
@fuanka1724 6 жыл бұрын
Thanks for making these awesome videos, you are a great teacher! :)
6 жыл бұрын
Glad you like them!
@AlexanderLebedev_sortafreel
@AlexanderLebedev_sortafreel 7 жыл бұрын
Amazingly useful video!
@adeyeyeayomide4442
@adeyeyeayomide4442 6 жыл бұрын
waooh! This is concise, succinct and informative
@Phantastischphil
@Phantastischphil 4 жыл бұрын
Thank you. I was searching for the code behind exceptions while using SOLO LEARN. Thank you for explaining that they are objects and how to construct and tailor specific instances!
@springinfialta106
@springinfialta106 7 жыл бұрын
It would be helpful to have a talk describing multiple exceptions within a block. Some programmers would say that each block should just do one very specific thing and would only require one try...except. However, sometimes you are doing a few very related things such as working with files and each of those steps might throw an exception. You don't necessarily want to chop up that piece of code into a bunch of separate functions. Even in your Factorial example. You could have multiple checks: 1) Is the type correct? 2) Is the passed in number an integer? 3) Is the passed in number >= 0 How are those tests integrated together? I've seen things like this which seem over the top: try code except exception else: try code except exception else: try etc Is there a better way?
7 жыл бұрын
The details of course depend on the situation and the programmer's sense of aesthetics. But as a general thought: If you have multiple checks, you can generally do them sequentially, one after another; so a deeply nested structure (which is awful) like your example is seldom necessary. And when it comes to input validation, type hints might also come in handy (kzbin.info/www/bejne/qKrXgZKsfs-tm6c). But at the end of the day: If you need to check a lot of things, you'll inevitably end up with a lot of boilerplate code!
@Usammityduzntafraidofanythin
@Usammityduzntafraidofanythin 5 жыл бұрын
There's also if else, which gives another layer. Taken from channel SentDex
@jyvben1520
@jyvben1520 Жыл бұрын
have functions that each test 1 condition, with specific try/except + raise the_error("message") and the main code has a generic try/except Exception as e, with the many functions in the try block. try: test_is_num(a_value) test_is_int(a_value) test_is_pos(a_value) # here we can do the work or in the else block except Exception as e: print("Error: bad input", a_value) print(e) # optional else: print("good input, we can work with this") finally: pass
@m.preacher2829
@m.preacher2829 4 жыл бұрын
very clear explanation,thanks
@cmdlp4178
@cmdlp4178 7 жыл бұрын
You can catch SyntaxErrors when importing or running code with eval/exec.
7 жыл бұрын
+cmdLP that's a good point, yes.
@denispmaciel
@denispmaciel 6 жыл бұрын
Thank you!
@FitLife6767
@FitLife6767 6 жыл бұрын
Yeah this one was very useful... It seems it was made specifically to address my issue...Thank you very much!
@davidreynolds9649
@davidreynolds9649 7 жыл бұрын
What is the document/environment you are using to display this?
7 жыл бұрын
It's a Jupyter Notebook, which is basically an IPython terminal in a webbrowser. Very useful!
@davidreynolds9649
@davidreynolds9649 7 жыл бұрын
thnx .... looks very cool :)
@gabrielkomanderzapata3189
@gabrielkomanderzapata3189 5 жыл бұрын
Nice video many thanks
@amateruss
@amateruss 6 жыл бұрын
WTF I thought your cam was a random picture of a dude on a beach having a vacation until I pressed the play button.
@ELHAUKEZ
@ELHAUKEZ 5 жыл бұрын
def riddle(): try: return 1 finally: return 2
@pizzaboiiiiiiiiiiiiiiiiiii1882
@pizzaboiiiiiiiiiiiiiiiiiii1882 3 жыл бұрын
keep going dude, way to hawaii
@vaibhavashrivastava9310
@vaibhavashrivastava9310 5 жыл бұрын
"i have a data frame with columns ID and date, If date is invalid how my python program can tell me which ID indexed with invalid date"
5 жыл бұрын
You can use the `isnull()` method. So say that your DataFrame is called `df` and your column is called `date`, then you can get the (indexes of) invalid dates with `df.date.isnull()`.
@schogaia
@schogaia 4 жыл бұрын
What is the benefit of using try: else:? I just put everything in the try block. I would appreciate if someone could explain this to me. Thank you
4 жыл бұрын
If you include too much code in the try block, it becomes difficult to know where Exceptions come from. So it's good practice to include as little code as possible in the try block.
@schogaia
@schogaia 4 жыл бұрын
@ thank you for the answer and thank you for great videos
@antongeorgiev1704
@antongeorgiev1704 5 жыл бұрын
Very nice series, thank you! fyi, saying there is no logic behind 0! = 1, just def, hurts my mathematician's hearth ;(
@maxvinella941
@maxvinella941 6 жыл бұрын
very interesting! thanks
@Dopeboyz789
@Dopeboyz789 5 жыл бұрын
How do you use this method in a df
@radonspace2098
@radonspace2098 3 жыл бұрын
I owe you a coffee.
@OrgBrent
@OrgBrent 3 жыл бұрын
Are you Dutch?
3 жыл бұрын
Ja dat klopt!
@bondbreaker3096
@bondbreaker3096 6 жыл бұрын
more video please
@dhananjaykansal8097
@dhananjaykansal8097 5 жыл бұрын
AWESOMEEEEE
@boobubuo
@boobubuo 6 жыл бұрын
esle ???? why ??? try esle before except block (inside "try except")... lol
Python tricks: Demystifying async, await, and asyncio
15:59
Sebastiaan Mathôt
Рет қаралды 94 М.
Application logging in Python | Python tricks
18:43
Sebastiaan Mathôt
Рет қаралды 11 М.
Amazing Parenting Hacks! 👶✨ #ParentingTips #LifeHacks
00:18
Snack Chat
Рет қаралды 20 МЛН
Секрет фокусника! #shorts
00:15
Роман Magic
Рет қаралды 117 МЛН
escape in roblox in real life
00:13
Kan Andrey
Рет қаралды 75 МЛН
Python tricks: Type hints and static type checking
14:15
Sebastiaan Mathôt
Рет қаралды 21 М.
Python Tutorial: Using Try/Except Blocks for Error Handling
10:34
Corey Schafer
Рет қаралды 698 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 942 М.
Starting a new Python project (regular expressions) [PythonLiveLessons #0]
37:05
Python Generators 2: send and yield
14:54
Sebastiaan Mathôt
Рет қаралды 9 М.
Profiling and optimizing your Python code | Python tricks
17:11
Sebastiaan Mathôt
Рет қаралды 71 М.
Object-Oriented Programming is Bad
44:35
Brian Will
Рет қаралды 2,3 МЛН
No, Einstein Didn’t Solve the Biggest Problem in Physics
8:04
Sabine Hossenfelder
Рет қаралды 291 М.