Great video! One consideration for other watchers: In some use cases, sending a 403 error back to the user is not always best practice. In terms of security, returning a 403 error tells a bad actor that private data definitely exists at that exact ID in your database. If you have security concerns about this (i.e. a brute force attack to undercover private blogs) you should just return a generic 404 error instead so that non-existent blogs and private blogs are indistinguishable to an attacker.
Another easy to follow video that covered an advanced topic. I like how you show the initial code, review how it may not be ideal, than show the improvements made as you explain the topic. Excellent viewer count for the first day -- you have a following. Congratulations and thanks for your time.
8:50 - Hi Arjan and thanks for the video :) A VERY important note that is not addressed at this point: you are using string interpolation to make your SQL query , which make it vulnerable to SQL injection attacks ☝ The sqlite3 documentation mention it explicitly: use placeholder if you want to dynamically write your SQL queries. I don't know if you speak about that later, but I would recommend to mention that at first, for the viewers who don't watch the video until the end. In your example, it would be possible to delete all your blogs just by typing some query in the url endpoint. Please let me know if I'm wrong 👍
The video is focusing more on exceptions and how to handle them better. The code is just an example so people shouldn't take it as best practice. What you're referring to is parameterised queries. I guess new programmers might see that and try it but from watching a few I think Arjan's videos expect you to have some programming experience.
Love it, man. I'm too addicted to these videos. Still want to say - Appreciate the detailed videos. Hope you find joy doing these. Also, be my private mentor. :D
Not doing anything with Python currently but I still love watching your videos since the concepts and ideas are generally applicable to programming. That said, having used a bit of Rust and Elm recently, I do appreciate being forced to reconcile errors. It slows you down a bit, sure, but help me to consider cases I might have glossed over in other languages. Having a Result type has really grown on me.
One thing I'd recommend is to add the top level route try excepts into a single decorator, and then reuse that decorator on each route. It really helps to reduce duplicate code and allows the function in the route to mainly be about the logic involved.
Your presentation style is fantastic. I really love the way you present the material as if we are sitting in the chair right next to you; makes the material really relatable. The retry decorator is a gem, so thanks for bringing that up because I have a Twitter bot that regularly loses its stream connection and this may be a great way to handle reconnects. Thanks Arjan.
Thank you Chuck. I’m happy that’s how you’re experiencing it, because I still have trouble behaving naturally when looking straight into a camera lens, haha. It’s a work in progress :).
Am pleased that your channel exists! Echoing many of the other connectors. Thank you for your continuing series designed to offer the dev a chance at implementing good dev practices. Python being one example language, many of the example videos' spirit applies to other languages. The videos have great pacing - good, simple modern example use cases to examine the neat of a topic.
I know it is a silly distinction, but one of the great things about this video is how you keep things to very simple subsets of the use cases. SO many other videos would have called out to some database with a huge amount of data in there and we would have no idea the actual structure of what we are querying. Now, in general, you shouldn't need to know all the rows that are there and that's not the biggest of deals (in the real world)... however... when you are trying to think carefully about how to think (which is the case with your videos), you want to be able to wrap your mind around the entire concept and you creating a DB here with just 2 entries is gold.
Thank you for describing how to handle exceptions in such a logical way. I have struggled with this is exact issue when writing hardware modules that communicate with internet connected devices.
Thank you! This is really helpful. Unfortunately in my role as a Data Architect/Data Engineer I have to write a lot of python code without having the possibility to challenge my code with other co-workers. These videos show me where I can improve my code to make it more reliable, more readable and avoid as much coupling and coherence as possible. THANK YOU SO MUCH!
This video was a bit longer than usual - I had a lot to cover, even after cutting out several minutes of my rambling :) Also check out my video about loops in Python if you like the discussion about programming languages features and why they exist: ruclips.net/video/X0DBP5pxJ_8/видео.html.
Errors have been around since the beginning of time. As an old, OLD, IBM programmer, I really appreciated the way that every error in a program had an "error number" and description that was published in the user manual. This meant that every ( known ) error could be tracked down and hopefully resolved. Since most of the programming of olden days was batch processing, it was a necessity to have the ABEND code to track down your problem. I realize this is overkill for most stuff today, but it would still be nice for every program to have a reference manual for those.
Funny, I absolutely hated the whole concept of "error numbers". File not found? And what file would that be referring to? Doesn't say, even though the interpreter clearly knew what file it was looking for at the moment the error occurred. Go figure it out yourself. The interpreter hiding behind a number while not giving the relevant information even though the relevant information (like the filename in this case) should be available, always felt sadistic to me.
The retry decorator is really great, thanks a lot! And thanks for the videos, a lot helpful, I do really appreciate the way you show things, not boring, not precise or redundant like a lot of resources found on the webzzz. 🍻
Fantastic Arjan, thank you for helping me understand exceptions and writing better code! I did not know about the finally: of a try block or that you could have two exceptions in one try block. I'm sure this sort of thing is in the docs but I learn better by doing/examples than by reading docs. So please keep up the great work, it's much appreciated!
Nice one. From your retry decorator. I finally know how to properly pass optional arguments to decorators using double wrap of the decorator. This has saved some code duplication for me. Cheers.
I did not know that the 'finally' keyword also fires when an uncaught exception is raised. I kind of assumed that it only triggered when you handled exceptions. Glad I know that now thanks.
You're welcome, Gertjan! That "feature" of the finally keyword is very useful, because it will run the cleanup code regardless of whether there was an exception or not.
3 года назад+25
04:09 Eek, don't teach people to use string formatting to create a database query! Especially when your ID is a string, this is a very bad habit to pick up. Use `?` placeholders instead, and let the database interface handle the substitution.
Thanks Arjan for creating these best of the class videos!!! I became fan. Would be waiting to see best practices for Async way of handling Database/File operation.
Very clear explanation of the different possibilities to treat errors. Personally I think that error handling must solve the problem and return to a "well known workflow" as soon as possible. That is, the lower level methods should treat exceptions at their level and avoid raising errors up to their callers. I usually make my methods return some kind of "simple and agreed error status" when possible, but not step up raising exceptions. And this also lets me create few or even no custom error classes at all.
As some one who hunts for vulnerabilities in my spare time, I can tell you that I **LOVE** poorly handled exceptions and stack traces. Just something to remember :)
I like your videos. Well paced, very informative and well explained. I usually find one or two things that I would do differently, but not in this one! I will definitely recommend this to my colleagues.
Rust's approach with an enum type Result::(Ok|Err) is by far the best. The control flow is not affected, and the compiler forces you to use/unwrap your value. I think Scala also has this but with different names.
8:50 - What about the case where sqlite throws an exception when trying to connect during line 37 (con = sqlite3.connect), and so the `con` variable is never assigned. Would placing the `con.close()` in a `finally` block throw an additional, unhandled exception? I LOVE your videos and am learning a TON. Thank you!!
Thank you and well spotted! I actually fixed this in last week’s video, where I check in the leave method of the context manager whether the conn variable actually contains a value.
This is also consistent with Hex / Clean Architecture way of thinking where you don't want any dependencies on concrete classes (like concrete database exceptions) inside domain / logic layers. For example FetchBlog could be imlpemented through a database call, filesystem lookup, http request. That is, avoid anything that could give away the technical implementation details of the outer layers. Also, even an Unauthorized Exception could be flat out wrong and never occur when imlpementing FetchBlog via filesystem lookup.
I need your advice. I need to write a function that will check the free balance for the purchase of goods, and also if there are not enough funds, then wite a warning about this in the log file with a list of variables (balance, used balance and cost of the goods). I see two possible solutions - 1) the necessary check is made and if there are not enough funds, then display a warning and return the value False. 2) the necessary check is made and if there are not enough funds, then call a custom exception with a list of necessary variables, and in the external function implement the exception catching and writing to the log. The question is which of the two options is preferable or share a more correct option.
I really like the contextlib module from the standard library to create context managers with a function. One thing I do not like about context managers is that they can hide other unrelated errors if not properly set up. I had this problem once and I will never forget about it, but it's still tricky. Logging everything helps a lot when debugging things like that.
Love the channel. Please make a video about structural design in python. How to make a large project that is clear and well structured. How to avoid function tunnels that need to deliver certain input to the bottom of the tunnel. For ex. creds to API call. I would also like to see ETL-videos. From API to process to database. Thank you!
Great video. Side note: you type so fast! Are you speeding up the video over the times that you are typing to save time, or are you just an insanely fast typist?
@@ArjanCodes LOL! I had a close friend and colleague who actually did type that fast - and hard. She always had a spare keyboard ready for when she broke the one she was using!! And when she was typing code that fast she was so immersed that you could have a brief conversations with her which she wouldn't remember afterwards. Brilliant, talented person. Hearing your 'fast forward' typing in the first video of yours I watched reminded me of her. RIP Allison.
I approach error handling by avoiding it as much as possible. I try to make as much as my logic as error free as possible and pass the successful results of error handled code into them. For example I prefer having something take in a file than a file name. That way I only have to handle read and/or write errors and not file not found, lack permission errors, etc.
Scala/Haskell both use error Monads which are a more SOLID compliant way of doing error handling and avoiding pretty much all the pitfalls of errors. This is a solution I was hoping to see discussed. Sadly it was missed as the already common best way of handling errors in less basic languages than python.
8:46 one other advantage of finally block over copy pasting the code inside execpt block, is that it garanties that the code within finally would be always executed, even, for example, if other exceptions are raised in your except block.
I really enjoy your videos, thanks for making them! You mentioned using both REST and GraphQL; it would be nice to have a video using the same logic for both, contrasting their differences :)
Thank you :D Could you make a video, especially about dependancy injection - for example if you want to inject a specific, already existing class. So where to create this class that then is injected in possibly multiple other classes.
Thank you and great suggestion, @IceCrasher! This video talks about a variation of what you're suggesting: ruclips.net/video/Kv5jhbSkqLE/видео.html. I'll definitely also consider doing a more in-depth dependency injection video.
@@ArjanCodes Thank you. I have already watched that video. If you’d make a more in-depth video, it would be terrific - I like very much your style of explaining things. Maybe a video, where you also take factories into account. A wonderful example could be if you want to read a config file, where your lamps at home are defined. Then all the lamps in this config file must be created. Afterward, the lamps need to be injected into multiple other classes. For example, in a Home_automation class (that is able to switch them on and off) as well as into a House_cleaning_scheduler (that tells you when to clean your lamps). It also would be very interesting, how you would organize all these classes and interfaces in your file hierarchy. Anyway, keep up the good work. :)
Why not make a db connection at the beginning when we run the web server, and then close it when we end the webserver or an exception occurred? Is that for security reasons?
In a production environment, that would definitely be the way to go. In that case you’d probably not use SQLite either, but connect to a database server instead. In this video, I wanted to keep things simple and focus on the resource cleanup part together with exceptions, that’s why I incorporated creating the connection inside each API function. I’ll perhaps do another video series where I focus on setting up a backend API with everything surrounding that.
Great video thanks. I am still trying to figure out when to use if else and check for the thing that causes the error rather than try except. I have mainly been doing if else such as checking if a file exists first, then checking I have permissions to view it, then that it is not already opened. It sounds like this could be something I add to my rest api calls in the code to handle a connection error because I am not sure how to do that with if else.
Just seen a video from uncle Bob where he mentioned that the only thing he wants to see in a 'try' block is the one line of code calling the function/method...
I’m a new student and need help to do this project: I have a port scanner script it works properly; it works in Pycharm using python3.9. I have to make a file and I call this file (Example.txt). On this example file, I have to do this: 3. If the Ports is open, it should create a file and add an entry for port number 4. In case of any exception for instance “host is not available”, “host name could not be resolved” or due to any other error, you need to write that exception into the same file. I’m not asking for you to do the project for me, I'm only asking ware I need to work or used in my script to accomplish this because it is my first time doing this and working with python too, and I have been struggling with this part one very bad. I can even send you the code, so you can look and only tell me what I’m doing bad and is not working. Or try to make one day a video about this because I have search for this subject and I have not seen anything showing how to do these things in a script.
wait a second, base class for every exception is BaseException, SystemExit and KeyboardInterrupt are inheriting from it, not from the usual Exception so it won't get caught by generic "except Exception" handlers (source: python 3 docs)
How would the fetch_blog work if there was a context manager used with the sqllite? I've heard it's a code smell to manually close things. Thanks, I should have just watched & waited before asking.
Would the "finally" clause really ever be executed if no exception is thrown in the try block (because of the return statement)? I would have thought that if no exception occurs def fun(): try: do_something() return some_value except: do_something_else() finally: do_yet_another_thing() is equivalent to def fun(): do_something() return some_value do_yet_another_thing() which in turn is equivalent to def fun(): do_something() return some_value
Shouldn't the "blog_lst_to_json" function be called one level above, in API routes? For me it seems like a high-level consideration how data is serialized, and also "json"-related stuff seems to belong to HTTP domain.
I mean, it's a good thing to have exceptions, so that I can better debug the code. But my code will be full of "try"s "except"s. Is there some way to address that?
Been a solo developer at work for a couple years and these are the exact type of tutorials I need.
Thank you Dan, happy you're enjoying the videos.
I understand you completely.
I second this! As a solo developer this is a great guideline and resource to further my own experience and knowledge. Thank you Arjan!
I can feel you 😬
Great video! One consideration for other watchers:
In some use cases, sending a 403 error back to the user is not always best practice. In terms of security, returning a 403 error tells a bad actor that private data definitely exists at that exact ID in your database.
If you have security concerns about this (i.e. a brute force attack to undercover private blogs) you should just return a generic 404 error instead so that non-existent blogs and private blogs are indistinguishable to an attacker.
Man, these videos are really well made, well paced, and the content/expertise is top tier
Thank you, Joshua, happy you enjoy them!
ID 2247524951
Another easy to follow video that covered an advanced topic. I like how you show the initial code, review how it may not be ideal, than show the improvements made as you explain the topic. Excellent viewer count for the first day -- you have a following. Congratulations and thanks for your time.
Thank you Brian, happy you’re enjoying it. And indeed, definitely a lot of views within a single day!
8:50 - Hi Arjan and thanks for the video :) A VERY important note that is not addressed at this point: you are using string interpolation to make your SQL query , which make it vulnerable to SQL injection attacks ☝ The sqlite3 documentation mention it explicitly: use placeholder if you want to dynamically write your SQL queries. I don't know if you speak about that later, but I would recommend to mention that at first, for the viewers who don't watch the video until the end.
In your example, it would be possible to delete all your blogs just by typing some query in the url endpoint. Please let me know if I'm wrong 👍
Ah well, you speak about that in the next video ^^ Too bad that RUclips doesn't give a way to add some erratum to uploaded videos.
Yep, unfortunately there’s no easy way to do that other that refer to it in the description.
The video is focusing more on exceptions and how to handle them better. The code is just an example so people shouldn't take it as best practice. What you're referring to is parameterised queries. I guess new programmers might see that and try it but from watching a few I think Arjan's videos expect you to have some programming experience.
Love it, man. I'm too addicted to these videos. Still want to say - Appreciate the detailed videos. Hope you find joy doing these. Also, be my private mentor. :D
Thanks Gamal! I don’t do private mentoring but if I ever decide to start doing that, you’ll be the first to know ;)
Not doing anything with Python currently but I still love watching your videos since the concepts and ideas are generally applicable to programming.
That said, having used a bit of Rust and Elm recently, I do appreciate being forced to reconcile errors. It slows you down a bit, sure, but help me to consider cases I might have glossed over in other languages. Having a Result type has really grown on me.
One thing I'd recommend is to add the top level route try excepts into a single decorator, and then reuse that decorator on each route. It really helps to reduce duplicate code and allows the function in the route to mainly be about the logic involved.
Your presentation style is fantastic. I really love the way you present the material as if we are sitting in the chair right next to you; makes the material really relatable. The retry decorator is a gem, so thanks for bringing that up because I have a Twitter bot that regularly loses its stream connection and this may be a great way to handle reconnects. Thanks Arjan.
Thank you Chuck. I’m happy that’s how you’re experiencing it, because I still have trouble behaving naturally when looking straight into a camera lens, haha. It’s a work in progress :).
Am pleased that your channel exists!
Echoing many of the other connectors. Thank you for your continuing series designed to offer the dev a chance at implementing good dev practices. Python being one example language, many of the example videos' spirit applies to other languages.
The videos have great pacing - good, simple modern example use cases to examine the neat of a topic.
Thank you, @solarcide - happy you are enjoying the videos!
I know it is a silly distinction, but one of the great things about this video is how you keep things to very simple subsets of the use cases. SO many other videos would have called out to some database with a huge amount of data in there and we would have no idea the actual structure of what we are querying. Now, in general, you shouldn't need to know all the rows that are there and that's not the biggest of deals (in the real world)... however... when you are trying to think carefully about how to think (which is the case with your videos), you want to be able to wrap your mind around the entire concept and you creating a DB here with just 2 entries is gold.
best channel for a python developer and software engineer in general
Thank you!
Quite helpful discourse on error handling. The logger decorator is cherry on top. It's going to help quite a lot with logging
Thank you for describing how to handle exceptions in such a logical way. I have struggled with this is exact issue when writing hardware modules that communicate with internet connected devices.
Glad it was helpful, Shane!
Great video! Very simple examples of complex topics that give a great picture of what I need to do.
Glad you enjoyed it!
Thank you! This is really helpful. Unfortunately in my role as a Data Architect/Data Engineer I have to write a lot of python code without having the possibility to challenge my code with other co-workers. These videos show me where I can improve my code to make it more reliable, more readable and avoid as much coupling and coherence as possible. THANK YOU SO MUCH!
Thankful for you Arjan, god bless you and much appreciated from an up and coming developer.
Thanks Sakshi. Glad that you liked it.
I'm improving my programming skills and gaining a deeper understanding of Python thanks to you!
This video was a bit longer than usual - I had a lot to cover, even after cutting out several minutes of my rambling :) Also check out my video about loops in Python if you like the discussion about programming languages features and why they exist: ruclips.net/video/X0DBP5pxJ_8/видео.html.
Woow, that context manager for a database connection. Learned something new today. Good stuff. Thanks!
Glad it was helpful, Fabio!
Hi, I’m from Costa Rica and I’m learning python right now, your videos have been really helpful, thanks for the great content.
Keep the good work 👍🏻
Hi! Glad to hear the videos are helpful to you!
Errors have been around since the beginning of time. As an old, OLD, IBM programmer, I really appreciated the way that every error in a program had an "error number" and description that was published in the user manual. This meant that every ( known ) error could be tracked down and hopefully resolved. Since most of the programming of olden days was batch processing, it was a necessity to have the ABEND code to track down your problem. I realize this is overkill for most stuff today, but it would still be nice for every program to have a reference manual for those.
Funny, I absolutely hated the whole concept of "error numbers". File not found? And what file would that be referring to? Doesn't say, even though the interpreter clearly knew what file it was looking for at the moment the error occurred. Go figure it out yourself. The interpreter hiding behind a number while not giving the relevant information even though the relevant information (like the filename in this case) should be available, always felt sadistic to me.
My new favorite programming channel
Thanks so much! Glad you’re enjoying the content!
You are my new favorite channel for coding! I'm subbed!
Thanks so much Charles, and welcome onboard ;).
Also solo devops at my job, this video was a good overview/refresher for exception handlers and context management. Cheers!
Thank you!
Me too man lol
Solo devops at my company is slowly turning me into a full stack engineer
The retry decorator is really great, thanks a lot! And thanks for the videos, a lot helpful, I do really appreciate the way you show things, not boring, not precise or redundant like a lot of resources found on the webzzz. 🍻
15:45 the horn , very funny :) LOL ... Great video, Thanks
You’re welcome ☺️
thank you Arjan ! please keep making videos. They are very inciteful
Amazing tutorial! I learned a lot. Thank you for creating it.
The exception decorator is pretty slick
Thank you very much for this series, it's so clean and to the point. Really high quality!!
Glad you like them!
So much fun to see that the contents of the SOM course are also touched in these videos! They are really helpful for my own projects :) Thanks Arjan!
Thanks Björn, glad you like the videos!
Fantastic Arjan, thank you for helping me understand exceptions and writing better code! I did not know about the finally: of a try block or that you could have two exceptions in one try block. I'm sure this sort of thing is in the docs but I learn better by doing/examples than by reading docs. So please keep up the great work, it's much appreciated!
Nice one.
From your retry decorator.
I finally know how to properly pass optional arguments to decorators using double wrap of the decorator. This has saved some code duplication for me. Cheers.
Thanks a lot, Joe - glad it helped you 😊
man these videos are so freaking good in all kinds of ways! good job Arjan
Thank you so much - glad you like them!
Nice video. Very easy to follow, and I especially enjoyed the discussion of different error handling paradimes at the end.
Thank you, Chris!
Nice video 2 years but still very useful , as always thanks for your time :)
Dude, AMAZING tutorial. Really amazing.
Thank you - glad that you liked it!
I did not know that the 'finally' keyword also fires when an uncaught exception is raised. I kind of assumed that it only triggered when you handled exceptions.
Glad I know that now thanks.
You're welcome, Gertjan! That "feature" of the finally keyword is very useful, because it will run the cleanup code regardless of whether there was an exception or not.
04:09 Eek, don't teach people to use string formatting to create a database query! Especially when your ID is a string, this is a very bad habit to pick up. Use `?` placeholders instead, and let the database interface handle the substitution.
Agreed, this was an oversight. It’s already fixed in the Git repository.
awesome thank you, explained it clearly while showing examples.
Thanks so much, glad the content is helpful!
Thanks Arjan for creating these best of the class videos!!! I became fan. Would be waiting to see best practices for Async way of handling Database/File operation.
Thanks for the suggestions, Pranab, and glad you enjoy the videos!
Wow, this video is very high quality. Thanks
Very clear explanation of the different possibilities to treat errors. Personally I think that error handling must solve the problem and return to a "well known workflow" as soon as possible. That is, the lower level methods should treat exceptions at their level and avoid raising errors up to their callers. I usually make my methods return some kind of "simple and agreed error status" when possible, but not step up raising exceptions. And this also lets me create few or even no custom error classes at all.
I love you man. Your knowledge and explanations are par excellence. Hope your channel will grow from strength to strength. Thank you
You’re welcome, glad to hear you like the content!
As some one who hunts for vulnerabilities in my spare time, I can tell you that I **LOVE** poorly handled exceptions and stack traces. Just something to remember :)
I like your videos. Well paced, very informative and well explained. I usually find one or two things that I would do differently, but not in this one!
I will definitely recommend this to my colleagues.
Your content is amazing!!! Thank you for sharing your expertise. It is super helpful!
You're so welcome!
This video is great! I taught myself Python so I look to channels like yours to help me bridge learned theory into practical application. Cheers
Thank you Daniel, glad you enjoyed the video. If you have any suggestions for topics, please let me know.
Thanks Arjan, content is really helpful
Rust's approach with an enum type Result::(Ok|Err) is by far the best. The control flow is not affected, and the compiler forces you to use/unwrap your value. I think Scala also has this but with different names.
8:50 - What about the case where sqlite throws an exception when trying to connect during line 37 (con = sqlite3.connect), and so the `con` variable is never assigned. Would placing the `con.close()` in a `finally` block throw an additional, unhandled exception?
I LOVE your videos and am learning a TON. Thank you!!
Thank you and well spotted! I actually fixed this in last week’s video, where I check in the leave method of the context manager whether the conn variable actually contains a value.
@@ArjanCodes Aha! Watching this right now! Thanks once again for EVERYTHING!
Thank you! Exactly what I needed. Any optimizations for networking errors?
thanks Arjan for making this series
You're welcome!
Very informative !
I thank you sir!
This is also consistent with Hex / Clean Architecture way of thinking where you don't want any dependencies on concrete classes (like concrete database exceptions) inside domain / logic layers. For example FetchBlog could be imlpemented through a database call, filesystem lookup, http request. That is, avoid anything that could give away the technical implementation details of the outer layers. Also, even an Unauthorized Exception could be flat out wrong and never occur when imlpementing FetchBlog via filesystem lookup.
You really know your stuff. Thanks for this.
Thanks so much Jagdish, glad the content is helpful!
I need your advice. I need to write a function that will check the free balance for the purchase of goods, and also if there are not enough funds, then wite a warning about this in the log file with a list of variables (balance, used balance and cost of the goods). I see two possible solutions - 1) the necessary check is made and if there are not enough funds, then display a warning and return the value False. 2) the necessary check is made and if there are not enough funds, then call a custom exception with a list of necessary variables, and in the external function implement the exception catching and writing to the log. The question is which of the two options is preferable or share a more correct option.
I really like the contextlib module from the standard library to create context managers with a function. One thing I do not like about context managers is that they can hide other unrelated errors if not properly set up. I had this problem once and I will never forget about it, but it's still tricky. Logging everything helps a lot when debugging things like that.
Falling in love with this channel
Thanks!
I'm a Python guy. Love your channel.
Thank you Zachary, glad you like it!
Amazing content. Thanks Arjan!
You’re welcome, glad you like it!
thank you so much sir! this has been really helpful!
Glad it helped!
Better far better than udemy courses. Keep growing & sharing this way of creating sensible content.
Thank you so much! And will do ;)
Great video, what keyboard are you using ?
Thanks Richard! I'm using a Keychron K2.
Great video ! Thank you for doing these !
Glad you like them, @Raccoon Teaches You !
Thank you for these vids. AMAZING! ☺
Glad you like them!
Great video! Love to see a video on documenting code.
Thank you, Samuel! That goes on my list 😊
now that's a cool video :) enjoyed watching, thank you
Glad you enjoyed it :)
Love the channel. Please make a video about structural design in python. How to make a large project that is clear and well structured. How to avoid function tunnels that need to deliver certain input to the bottom of the tunnel. For ex. creds to API call. I would also like to see ETL-videos. From API to process to database. Thank you!
Thank you, I’ll definitely consider those topics!
@@ArjanCodes thanks! Enjoy The weekend!
great video. learnt about the part of python usually untouched by tutors.
Thank you Pratham, glad you like it!
Please keep up the stellar work!
Thanks Jonathan, will do!
13:24 sqlite3 actually has a builtin support of context manager, sqlite3.connect() creates an objects with __enter__/__exit__ methods
Great video.
Side note: you type so fast! Are you speeding up the video over the times that you are typing to save time, or are you just an insanely fast typist?
Thanks Brian. I'm a horribly slow typer actually, haha. I speed those parts up to not make you endure that :).
@@ArjanCodes hahaha, thanks. Now I don't feel so slow! 🤪
@@ArjanCodes LOL! I had a close friend and colleague who actually did type that fast - and hard. She always had a spare keyboard ready for when she broke the one she was using!! And when she was typing code that fast she was so immersed that you could have a brief conversations with her which she wouldn't remember afterwards. Brilliant, talented person. Hearing your 'fast forward' typing in the first video of yours I watched reminded me of her. RIP Allison.
I approach error handling by avoiding it as much as possible. I try to make as much as my logic as error free as possible and pass the successful results of error handled code into them. For example I prefer having something take in a file than a file name. That way I only have to handle read and/or write errors and not file not found, lack permission errors, etc.
Scala/Haskell both use error Monads which are a more SOLID compliant way of doing error handling and avoiding pretty much all the pitfalls of errors. This is a solution I was hoping to see discussed. Sadly it was missed as the already common best way of handling errors in less basic languages than python.
I did a follow-up video to this one dedicated to Monadic error handling, see: ruclips.net/video/J-HWmoTKhC8/видео.html.
8:46 one other advantage of finally block over copy pasting the code inside execpt block, is that it garanties that the code within finally would be always executed, even, for example, if other exceptions are raised in your except block.
Great job! I really enjoy your videos.
Thank you very much, Robert!
I really enjoy your videos, thanks for making them!
You mentioned using both REST and GraphQL; it would be nice to have a video using the same logic for both, contrasting their differences :)
Good idea, thank you!
Such a good video!
Thanks so much!
Thank you :D Could you make a video, especially about dependancy injection - for example if you want to inject a specific, already existing class. So where to create this class that then is injected in possibly multiple other classes.
Thank you and great suggestion, @IceCrasher! This video talks about a variation of what you're suggesting: ruclips.net/video/Kv5jhbSkqLE/видео.html. I'll definitely also consider doing a more in-depth dependency injection video.
@@ArjanCodes Thank you. I have already watched that video. If you’d make a more in-depth video, it would be terrific - I like very much your style of explaining things.
Maybe a video, where you also take factories into account. A wonderful example could be if you want to read a config file, where your lamps at home are defined. Then all the lamps in this config file must be created. Afterward, the lamps need to be injected into multiple other classes. For example, in a Home_automation class (that is able to switch them on and off) as well as into a House_cleaning_scheduler (that tells you when to clean your lamps).
It also would be very interesting, how you would organize all these classes and interfaces in your file hierarchy.
Anyway, keep up the good work. :)
Thank you @IceCrasher, will keep this in mind for my planning!
Why not make a db connection at the beginning when we run the web server, and then close it when we end the webserver or an exception occurred? Is that for security reasons?
In a production environment, that would definitely be the way to go. In that case you’d probably not use SQLite either, but connect to a database server instead. In this video, I wanted to keep things simple and focus on the resource cleanup part together with exceptions, that’s why I incorporated creating the connection inside each API function. I’ll perhaps do another video series where I focus on setting up a backend API with everything surrounding that.
@@ArjanCodes Looking forward to that video!
You need to put a try: block around your close() else if the DB was never opened (open failed) the close will raise an exception
Great video thanks. I am still trying to figure out when to use if else and check for the thing that causes the error rather than try except. I have mainly been doing if else such as checking if a file exists first, then checking I have permissions to view it, then that it is not already opened. It sounds like this could be something I add to my rest api calls in the code to handle a connection error because I am not sure how to do that with if else.
You can also do like return Try(something) like in crazy scala
Amazing work
Thanks Amy, Glad that you liked it.
Just seen a video from uncle Bob where he mentioned that the only thing he wants to see in a 'try' block is the one line of code calling the function/method...
I’m a new student and need help to do this project:
I have a port scanner script it works properly; it works in Pycharm using python3.9.
I have to make a file and I call this file (Example.txt).
On this example file, I have to do this:
3. If the Ports is open, it should create a file and add an entry for port number
4. In case of any exception for instance “host is not available”, “host name could not be resolved” or
due to any other error, you need to write that exception into the same file.
I’m not asking for you to do the project for me, I'm only asking ware I need to work or used in my script to accomplish this because it is my first time doing this and working with python too, and I have been struggling with this part one very bad. I can even send you the code, so you can look and only tell me what I’m doing bad and is not working.
Or try to make one day a video about this because I have search for this subject and I have not seen anything showing how to do these things in a script.
wait a second, base class for every exception is BaseException, SystemExit and KeyboardInterrupt are inheriting from it, not from the usual Exception so it won't get caught by generic "except Exception" handlers
(source: python 3 docs)
Awesome video, keep up the incredible work! :)
Thank you - will do ;)
Can you use just "except e" to catch all exceptions? If so, what are the implications of doing that?
When would be the next movie coming out of the 'MUMMY' series? This guys really seems the lead actor :P
How would the fetch_blog work if there was a context manager used with the sqllite? I've heard it's a code smell to manually close things. Thanks, I should have just watched & waited before asking.
Would the "finally" clause really ever be executed if no exception is thrown in the try block (because of the return statement)? I would have thought that if no exception occurs
def fun():
try:
do_something()
return some_value
except:
do_something_else()
finally:
do_yet_another_thing()
is equivalent to
def fun():
do_something()
return some_value
do_yet_another_thing()
which in turn is equivalent to
def fun():
do_something()
return some_value
Shouldn't the "blog_lst_to_json" function be called one level above, in API routes? For me it seems like a high-level consideration how data is serialized, and also "json"-related stuff seems to belong to HTTP domain.
I mean, it's a good thing to have exceptions, so that I can better debug the code. But my code will be full of "try"s "except"s. Is there some way to address that?
Really good.
Thank you Ivan!
Excellent!
Thank you, Syberen!
16:00 Lol. Great video
Thanks!
raise exception vs return mesaages what wud u prefer ?