Using the Project Anywhere
In this lesson, you’ll experiment with calling snakesay
in different ways:
- With
-m
- Without
-m
- From the REPL
00:00
Now, that means that we can basically call it any way we like and from anywhere. Yeah, let’s try it. So now, we remember that we had issues where we couldn’t do both python -m snakesay
and python snakesay
. Now we should be able to do both.
00:16
So now we can just do snakesay Sleep tight, little man-cub
. Cool, that’s working. And that was the one that wasn’t working before, because in the code we were saying from snakesay import snake
.
00:33
That broke that way. This meant that we needed to use the -m
flag. Exactly. But now it’s working. And I assume that the -m
flag will also work.
00:45
Great. It does. And this is even cooler now because now you can even go out of this project. Wow. And you can now run your -m
version …
01:09
and it runs from here as well. Okay, great. So if we go into python
—Yes, so now you can even import snakesay
, and we even now run the from snakesay import snake
.
01:27
Yeah, exactly, and run our snake.say()
command here.
01:41 Great. So this gives us a load of flexibility. Yeah, it gives you all the conveniences of installed packages because that’s exactly what we’ve done. And now there’s no reason to ever think about the path again. Right.
01:54
And also, it prevents us from having to think about relative imports as well because even if we’re in a very deep subfolder of our package, we can still just say from snakesay import snake
. Yep, so the imports are all consistent all the time.
02:10
You can just always start at snakesay
and find whatever you’re looking for.
Become a Member to join the conversation.
adityahpatel on Nov. 17, 2023
This is not remember-able. @00:36 time stamp in Video titled (Using the project anywhere)..why do we have to do from snakesake import snake instead of import snake. They are in the same folder! Why this quirk?