Import String and Calc
00:00
Next, you need to import the string
and the calc
modules, but you can’t just import them with a plain import string
or import calc
statement.
00:10
You also need to import the helpers
package because that’s how you structured the project. There is a helpers/
folder, and inside the helpers/
folder, there is a string.py
and the calc.py
file next to the __init__.py
file.
00:25
To import from a package, you write from
and then the package name, which in this case is helpers
. And then you need to declare the modules you want to import.
00:35
In this case, it’s import string
.
00:40
Now we have two options. Since both string
and calc
are in the helpers
package, you can just add a comma behind string
00:48
and put calc
after it. So the import statement would be from helpers
import string, calc
, or you can be more verbose and add a new line and there say from helpers
import calc
. Both are valid.
01:06 I will stick with this one because it’s a bit more verbose, which is fine for this course, but you might have had a different solution, and as long as it works, it’s fine.
01:15
So let’s see if my version works. Save the main.py
file and run it in the interactive window. And if you don’t see any error, then it works.
01:27
And that means you can remove the comment that imports the string
and calc
modules so that at the beginning of the file after the main.py
comment, you have two import statements: from helpers import string
, and from helpers import calc
.
Become a Member to join the conversation.