Been a solo developer at work for a couple years and these are the exact type of tutorials I need.
@ArjanCodes3 жыл бұрын
Thank you Dan, happy you're enjoying the videos.
@MaBuSt3 жыл бұрын
I understand you completely.
@vfvermeers62592 жыл бұрын
I second this! As a solo developer this is a great guideline and resource to further my own experience and knowledge. Thank you Arjan!
@princeroshan4105 Жыл бұрын
I can feel you 😬
@kevinjerome59542 жыл бұрын
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.
@joshuamcdonald58503 жыл бұрын
Man, these videos are really well made, well paced, and the content/expertise is top tier
@ArjanCodes3 жыл бұрын
Thank you, Joshua, happy you enjoy them!
@gybsjskkddnnd39613 жыл бұрын
ID 2247524951
@brianhacker73463 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
Thank you Brian, happy you’re enjoying it. And indeed, definitely a lot of views within a single day!
@michaeldebetaz2 жыл бұрын
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 👍
@michaeldebetaz2 жыл бұрын
Ah well, you speak about that in the next video ^^ Too bad that KZbin doesn't give a way to add some erratum to uploaded videos.
@ArjanCodes2 жыл бұрын
Yep, unfortunately there’s no easy way to do that other that refer to it in the description.
@vman2kay2 жыл бұрын
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.
@murghay013 жыл бұрын
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
@ArjanCodes3 жыл бұрын
Thanks Gamal! I don’t do private mentoring but if I ever decide to start doing that, you’ll be the first to know ;)
@zarblitz3 жыл бұрын
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.
@MaBuSt3 жыл бұрын
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.
@nickscott98323 жыл бұрын
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.
@cetilly3 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
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 :).
@ArjanCodes3 жыл бұрын
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: kzbin.info/www/bejne/jmGnc4Nrpd19lZo.
@solarcide3 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
Thank you, @solarcide - happy you are enjoying the videos!
@janHodle2 жыл бұрын
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!
@mootaizaz63783 жыл бұрын
best channel for a python developer and software engineer in general
@ArjanCodes3 жыл бұрын
Thank you!
@vikas416 Жыл бұрын
Quite helpful discourse on error handling. The logger decorator is cherry on top. It's going to help quite a lot with logging
@seattleshane5693 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
Glad it was helpful, Shane!
@johncrunk80383 жыл бұрын
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.
@petersteenkamp3 жыл бұрын
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.
@lautaroleonhardt26002 жыл бұрын
I'm improving my programming skills and gaining a deeper understanding of Python thanks to you!
@omarcrosbyАй бұрын
Your channel is a goldmine!
@cs37053 жыл бұрын
Also solo devops at my job, this video was a good overview/refresher for exception handlers and context management. Cheers!
@ArjanCodes3 жыл бұрын
Thank you!
@chriskeo3923 жыл бұрын
Me too man lol Solo devops at my company is slowly turning me into a full stack engineer
@zetowaw2 жыл бұрын
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 👍🏻
@ArjanCodes2 жыл бұрын
Hi! Glad to hear the videos are helpful to you!
@joegaffney80063 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
Thanks a lot, Joe - glad it helped you 😊
@ehkpnwvthuvibaoibx3 жыл бұрын
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. 🍻
@Khushpich3 жыл бұрын
My new favorite programming channel
@ArjanCodes3 жыл бұрын
Thanks so much! Glad you’re enjoying the content!
@FabioKasper3 жыл бұрын
Woow, that context manager for a database connection. Learned something new today. Good stuff. Thanks!
@ArjanCodes3 жыл бұрын
Glad it was helpful, Fabio!
@-bjorn-54653 жыл бұрын
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!
@ArjanCodes3 жыл бұрын
Thanks Björn, glad you like the videos!
@joaodiasconde3 жыл бұрын
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.
@CharleswoodSpudzyofficial3 жыл бұрын
You are my new favorite channel for coding! I'm subbed!
@ArjanCodes3 жыл бұрын
Thanks so much Charles, and welcome onboard ;).
@shashishekhar----2 жыл бұрын
Thankful for you Arjan, god bless you and much appreciated from an up and coming developer.
@ArjanCodes2 жыл бұрын
Thanks Sakshi. Glad that you liked it.
2 жыл бұрын
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.
@davido25133 жыл бұрын
The exception decorator is pretty slick
@meh.75393 жыл бұрын
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 :)
@mauisam13 жыл бұрын
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!
@erikjones12665 ай бұрын
Great video! Very simple examples of complex topics that give a great picture of what I need to do.
@ArjanCodes5 ай бұрын
Glad you enjoyed it!
@jumaxeno5004 Жыл бұрын
thank you Arjan ! please keep making videos. They are very inciteful
@yjallan3 жыл бұрын
man these videos are so freaking good in all kinds of ways! good job Arjan
@ArjanCodes3 жыл бұрын
Thank you so much - glad you like them!
@12valmirjr3 жыл бұрын
Thank you very much for this series, it's so clean and to the point. Really high quality!!
@ArjanCodes3 жыл бұрын
Glad you like them!
@chrysolite133 жыл бұрын
Nice video. Very easy to follow, and I especially enjoyed the discussion of different error handling paradimes at the end.
@ArjanCodes3 жыл бұрын
Thank you, Chris!
@abdelghafourfid82162 жыл бұрын
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.
@gertjanvandenbroek16202 жыл бұрын
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.
@ArjanCodes2 жыл бұрын
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.
@pranabsg3 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
Thanks for the suggestions, Pranab, and glad you enjoy the videos!
@danielellis60943 жыл бұрын
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
@ArjanCodes3 жыл бұрын
Thank you Daniel, glad you enjoyed the video. If you have any suggestions for topics, please let me know.
@cosmicblack Жыл бұрын
Nice video 2 years but still very useful , as always thanks for your time :)
@ren98122 жыл бұрын
13:24 sqlite3 actually has a builtin support of context manager, sqlite3.connect() creates an objects with __enter__/__exit__ methods
@mr.madness7721 Жыл бұрын
Amazing tutorial! I learned a lot. Thank you for creating it.
@darshake12 жыл бұрын
I love you man. Your knowledge and explanations are par excellence. Hope your channel will grow from strength to strength. Thank you
@ArjanCodes2 жыл бұрын
You’re welcome, glad to hear you like the content!
@malteplath3 жыл бұрын
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.
@MagnusAnand2 жыл бұрын
Dude, AMAZING tutorial. Really amazing.
@ArjanCodes2 жыл бұрын
Thank you - glad that you liked it!
@haristan19603 жыл бұрын
thanks Arjan for making this series
@ArjanCodes3 жыл бұрын
You're welcome!
@SP-db6sh3 жыл бұрын
Better far better than udemy courses. Keep growing & sharing this way of creating sensible content.
@ArjanCodes3 жыл бұрын
Thank you so much! And will do ;)
@manonthedollar3 жыл бұрын
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!!
@ArjanCodes3 жыл бұрын
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.
@manonthedollar3 жыл бұрын
@@ArjanCodes Aha! Watching this right now! Thanks once again for EVERYTHING!
@BillusTinnus2 жыл бұрын
Wow, this video is very high quality. Thanks
@zachary0073 жыл бұрын
I'm a Python guy. Love your channel.
@ArjanCodes3 жыл бұрын
Thank you Zachary, glad you like it!
@mrswats3 жыл бұрын
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.
@TJ-hs1qm4 ай бұрын
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.
@benatakaan613 Жыл бұрын
Your content is amazing!!! Thank you for sharing your expertise. It is super helpful!
@ArjanCodes Жыл бұрын
You're so welcome!
@talhaamir90233 жыл бұрын
Falling in love with this channel
@ArjanCodes3 жыл бұрын
Thanks!
@mohammedkhalid93173 жыл бұрын
Thanks Arjan, content is really helpful
@willTryAgainTmrw3 жыл бұрын
great video. learnt about the part of python usually untouched by tutors.
@ArjanCodes3 жыл бұрын
Thank you Pratham, glad you like it!
@djbroake98102 жыл бұрын
awesome thank you, explained it clearly while showing examples.
@ArjanCodes2 жыл бұрын
Thanks so much, glad the content is helpful!
@SamuelTaylorUK3 жыл бұрын
Great video! Love to see a video on documenting code.
@ArjanCodes3 жыл бұрын
Thank you, Samuel! That goes on my list 😊
@whkoh76192 жыл бұрын
Amazing content. Thanks Arjan!
@ArjanCodes2 жыл бұрын
You’re welcome, glad you like it!
@jonathanheadley27293 жыл бұрын
Please keep up the stellar work!
@ArjanCodes3 жыл бұрын
Thanks Jonathan, will do!
@naveenv30973 жыл бұрын
15:45 the horn , very funny :) LOL ... Great video, Thanks
@ArjanCodes3 жыл бұрын
You’re welcome ☺️
@raccoonteachesyou3 жыл бұрын
Great video ! Thank you for doing these !
@ArjanCodes3 жыл бұрын
Glad you like them, @Raccoon Teaches You !
@TinBryn3 жыл бұрын
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.
@jagdish1o12 жыл бұрын
You really know your stuff. Thanks for this.
@ArjanCodes2 жыл бұрын
Thanks so much Jagdish, glad the content is helpful!
@SuperRealhigh2 жыл бұрын
Very informative ! I thank you sir!
@robertbrummayer49083 жыл бұрын
Great job! I really enjoy your videos.
@ArjanCodes3 жыл бұрын
Thank you very much, Robert!
@yuriytigiev88162 жыл бұрын
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.
@ondskabenselv3 жыл бұрын
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 :)
@ArjanCodes3 жыл бұрын
Good idea, thank you!
@MonaCodeLisa Жыл бұрын
now that's a cool video :) enjoyed watching, thank you
@ArjanCodes Жыл бұрын
Glad you enjoyed it :)
@LoveisHell853 жыл бұрын
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!
@ArjanCodes3 жыл бұрын
Thank you, I’ll definitely consider those topics!
@LoveisHell853 жыл бұрын
@@ArjanCodes thanks! Enjoy The weekend!
@plexq3 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
I did a follow-up video to this one dedicated to Monadic error handling, see: kzbin.info/www/bejne/gF6riKClibCbeZo.
@imajindevon3 жыл бұрын
Such a good video!
@ArjanCodes3 жыл бұрын
Thanks so much!
@khalilrouatbi63452 жыл бұрын
thank you so much sir! this has been really helpful!
@ArjanCodes2 жыл бұрын
Glad it helped!
@adjbutler3 жыл бұрын
Thank you for these vids. AMAZING! ☺
@ArjanCodes3 жыл бұрын
Glad you like them!
@andrewwhyte93292 жыл бұрын
Thank you! Exactly what I needed. Any optimizations for networking errors?
@ComputerScienceSimplified3 жыл бұрын
Awesome video, keep up the incredible work! :)
@ArjanCodes3 жыл бұрын
Thank you - will do ;)
@snoopyjc2 жыл бұрын
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
@Amy-ve3ke2 жыл бұрын
Amazing work
@ArjanCodes2 жыл бұрын
Thanks Amy, Glad that you liked it.
@AnIceCrasher3 жыл бұрын
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.
@ArjanCodes3 жыл бұрын
Thank you and great suggestion, @IceCrasher! This video talks about a variation of what you're suggesting: kzbin.info/www/bejne/gaeYm5uYiNCkgqc. I'll definitely also consider doing a more in-depth dependency injection video.
@AnIceCrasher3 жыл бұрын
@@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. :)
@ArjanCodes3 жыл бұрын
Thank you @IceCrasher, will keep this in mind for my planning!
@programminginterviewsprepa77102 жыл бұрын
You can also do like return Try(something) like in crazy scala
@neotodsoltani59023 жыл бұрын
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?
@ArjanCodes3 жыл бұрын
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.
@-bjorn-54653 жыл бұрын
@@ArjanCodes Looking forward to that video!
@guocity6 ай бұрын
Can you use just "except e" to catch all exceptions? If so, what are the implications of doing that?
@kosmonautofficial2962 жыл бұрын
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.
@mathmo2 жыл бұрын
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
@evilwizard79313 жыл бұрын
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.
@andreo40813 жыл бұрын
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...
@khushaltrivedi98292 жыл бұрын
raise exception vs return mesaages what wud u prefer ?
@BrianOSheaPlus3 жыл бұрын
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?
@ArjanCodes3 жыл бұрын
Thanks Brian. I'm a horribly slow typer actually, haha. I speed those parts up to not make you endure that :).
@BrianOSheaPlus3 жыл бұрын
@@ArjanCodes hahaha, thanks. Now I don't feel so slow! 🤪
@michaelcorvin11293 жыл бұрын
@@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.
@3dcbd393ce3 жыл бұрын
3:41 Please don't teach people to write SQL queries by joining strings, that's how you get generations of coders writing trivially vulnerable code. The correct form is exactly the same length: cur.execute("SELECT * FROM blogs WHERE id=?", [id])
@ArjanCodes3 жыл бұрын
Good point, I overlooked that in this example. I’ll update it in the Git repository. I rarely use SQL queries directly anymore, and mostly rely on ORMs, which automatically take care of these vulnerabilities.
@TheRich1072 жыл бұрын
Great video, what keyboard are you using ?
@ArjanCodes2 жыл бұрын
Thanks Richard! I'm using a Keychron K2.
@rafy-ivanmorales30772 жыл бұрын
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.
@barciewicz2 жыл бұрын
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.
@markblacket89003 жыл бұрын
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)
@ivanherreros77733 жыл бұрын
Really good.
@ArjanCodes3 жыл бұрын
Thank you Ivan!
@syberen3 жыл бұрын
Excellent!
@ArjanCodes3 жыл бұрын
Thank you, Syberen!
@sushantrocks3 жыл бұрын
Great stuff
@ArjanCodes3 жыл бұрын
Thank you!
@sushantrocks3 жыл бұрын
@@ArjanCodes I always find it hard to decide where to log the exception, where to consume it and where to raise. I found what works is to first decide and define the exceptions for the module. Then make sure the public methods return those only. Private methods do the logging and raise what they want.