Create the Folder Structure
00:00 The first part of the challenge is creating the package structure. We need a folder named
00:16
inside the folder, a helpers
package with the modules __init__.py
, string.py
, and calc.py
. At this point, you may think, like, those comments are a little bit sparse at the beginning.
00:36
There is just this word project_exercises
, Inside the folder: helpers package
, and then the three filenames __init__
, string.py
and calc.py
.
00:45
And I agree with you, but I will delete these comments in a moment. It’s just kind of like a cheat sheet for me, what files and folders I need to create. This file here is not saved yet, but actually it’s a good idea to use this file as our starting file, which will be the __init__.py
file.
01:05
And this one should be inside a project_exercises/
folder inside the helpers
package. And by saving this file, I will create this folder structure.
01:14
Now I go to the desktop and create a new folder named project_exercises/
.
01:25
And then when I’m in this folder, I create another folder named helpers/
.
01:34
And there I save this file as __init__.py
or short __init__.py
.
01:47
Again, you need the __init__.py
file to make the helpers/
folder an actual Python package. Without the __init__.py
file, the folder would be just a regular Python folder.
02:00
And you don’t have something like a regular package. You have something else in Python, but you don’t have to bother about this. Now just make sure that you have the __init__.py
file.
02:12
On the left side of my screen, you can see that the folder structure was created. So we have a project_exercises/
folder, a helpers/
folder, and in there is an __init__.py
file.
02:24
That’s the first file that we need to create. The next one is string.py
. So I create a new IDLE editor window. I add the comment helpers/string.py
to it and save the file next to the __init__.py
file inside the helpers/
folder.
02:52
Let’s go back to the __init__.py
file where we have all the comments. And there was a third file that you need to create. It’s called calc.py
.
03:01
So again, create a new editor window and save this file next to __init__.py
and string.py
as calc.py
.
03:16
This time again, let’s add a comment on top, which gives us the filename, which in this case is inside the helpers/
folder, calc.py
.
03:28
Going back to the __init__.py
file, you can remove all the comments that were in there and just add __init__.py
as a comment. Do __init__.py
as a comment.
03:39
And with that, you have solved the first part of the challenge, creating a project_exercises/
folder. And within the project_exercises/
folder, you create a package named helpers
and three files: __init__.py
, calc.py
, and string.py
.
03:52
It’s just a folder with three Python files, but since there is the __init__
file, it’s a package.
Become a Member to join the conversation.