Add a Main Module (Solution)
There would be ways to save it somewhere else, but in this case, it’s the most straightforward way to just save it next to
greeter because that way you can import it without any big adjustments.
I will add the filename on top, and now just like last time, I will add comments of the things that you need to do. So create a module named
main.py. We did this, and now it should import
greet() takes one argument, which is
name. So if we run this right now, we’ll get an error. And for this moment, it’s okay to get an error because that way we also see that we are actually accessing the
So let’s save it and run it. Just like expected, we get a
greet() is missing 1 required positional argument, which is
name. That is the last part of this exercise: call the function with the argument
Now maybe at this point you spot something interesting because I didn’t solve the exercise exactly like it was requested. The request was to import
greet() from the
greeter module, but I actually imported the
greeter module and not the
And now you need to call the function with the argument
"Real Python". So let’s copy that
"Real Python" string from the comment and paste it as an argument in
greeter.greet() inside the parentheses, save it, and run it.
Become a Member to join the conversation.