Welcome back.
One of the common patterns when working with files is to actually put them in a try except lock.
So in here we can say try and actually put them.
Like this and try out to see if the file exists so we can say.
Except.
And let's say.
File not found error, which we've seen before.
And here I can say as air and inside will say print file does not exist.
So that now if I run this and remember in our current directory, we don't have sad text.
If I run this.
I get an error file does not exist.
We can even raise this error if we want it to.
So we can say raise error.
So now it works as expected.
Get filed does not exist and then give a file not found error.
So this is a common way to work with files to handle different errors.
Another common one with.
Files.
Is this idea of an IO error and an IO error?
Usually happens when the computer or the machine you're on has some issue reading or writing or doing
any sort of IO operation.
So you can have something like IO error in here and raise that error if you want.
Again if I run this file not found error.
If for some reason I give it a weird mode to do.
I get an unsupported operation error.
The options are endless, but I hope by now you have an idea of how to do file.
Oh, but let's do a fun exercise, because up until now we haven't really done anything exciting.
We just read a bunch of texts from a file and that was it.
Nothing that creator.
Right?
So let's do something fun.
In the next video, we're going to try and build a translator.
That's right.
I'll see you in the next video.
Bye bye.