Hey, in today's bonus example, I want to work on yesterday's bonus example where we build this script.
If you don't have this, you can find it attached in the lecture resources in this lecture for your
convenience.
The script we developed yesterday in bonus examples.
So what it does is it allows the user to enter FT and inches such as 312 and then it replies.
With this message, converting those feet and inches to meters.
And then it also says if that kids can use this light or not, depending on how tall that kid is.
So if it's below one meter.
That's kids cannot use the slides, otherwise they can use it as it is the case here.
1.2 metres.
Now we want to improve this script today.
By splitting it across different files.
Of importing those files in the main file.
So how would we do this?
Well, you probably know that we normally take the functions and put them in separate files.
So we have a post function.
Which pauses the string that the user enters in the command line and it returns a dictionary.
Then we have this convert function which gets FT and inches as numbers.
And it converts them to meters.
What I'll do now is I will consider that this program may become bigger in the future.
So I would go and right click on bonus.
This is a folder where bonus 14 is.
So Bono's 14 is an empty file and in bonus 14 I'm going to place all the codes of bonus 13.
So copied and pasted here.
And then I'm going to put this function into a separate file.
You can do that manually by creating a file inside.
Bonus of bonus is the folder which contains bonus 14.
So in the same folder you want to manually create a new file or you can use the par charm refactoring
feature to create that file automatically.
For that you need to select.
The function.
The entire function and right click and go to refactor and then you want to go to move.
So you want to move that function to another file.
So you want to move it from bonus 14 the current file to another file.
So let's say this is going to be.
Passers, passers.
You can just say passers or you can say passers.
14.
Wherever you prefer, I'll just keep it.
Parsers $0.14 and press on refactor.
This is what happened now.
One is that the function purser disappeared from Bones 14.
Second is that this line was added by Parcham charm.
This is saying from bonus that Porsche's 14 import pause parse was the name of the function.
Bonus is the name of this folder and parsers 14 is the file that was created by Power charm.
So parsers 14 is this file.
And the this file contains the definition of the parse function.
So this is an automatic process that offers.
But you can, of course, do that manually.
As I was explaining you, right click, create the file, put the function in there, and then import
parts from here.
Now, the way to import powers is.
There are two ways actually.
So this is one way from bonus dot passers for teen import pause or both.
You can also say just from posters for teen.
Import pass.
This would also work.
This works because pastors 14 and bonus 14 are in the same directory.
So this works.
But this also works because bonus is located in the project directory in the patch or project directory.
And that directory is also.
Included in the namespace, so both versions are fine to use.
Let's try the same with the convert function.
I'm going to right click over convert.
Go to refactor, go again to move.
This time we want to give this another name.
So converters maybe 14.
Press refactor and again the convert function was moved out of here.
This line was added and a converters 14 dot p file was generated with the definition of convert inside.
So that is our front end.
Now we get those functions, so we have them here and we ask the user to enter, feed on inches.
We create this variable pause equal to pause filled inches.
So you see that post is directly referred to as opposed to being serves 14.
This would also work, but you'd have to do import poor service 14, which is yet another way of importing.
So feel free to use any of them.
I'll just keep it as it is.
Supports.
And then we got the results.
We print out that string.
We check if the result is less than one and we print that.
String.
Otherwise, we print that other string.
So if I run this, it's going to work just fine.
Right.
So that was about this video I used to modules.
This time you could also use one single module and put both the convert and the pause function in one
single file.
Why did I use two files?
Well, because I think these functions are a bit different from each other.
So one is for parsing, another is for converting.
So.
I foresee that in the future I'll have more passing functions and that will allow me to extend the program
easier, the app easier.
So later I can just add more pass functions here.
Maybe I want to pause different.
Metric units.
So I can add those functions in here, although it is debatable whether it is a good idea to put both
converts and parts in one single file.
So both ways are fine.
Don't overthink.
Think about that.
And that was about this video.
Thanks a lot.
See you later.