Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
How is check_please.py being run successfully if the function is never called in the python file check_please.py? Also,
Also, why does this function have two parameters if we don't use the parameters? That is, I can call the function with the two variables I want, however the input function asks me again for the variables I already specified.
Chris FreemanTreehouse Moderator 67,515 Points
Hey Nathaniel Camorlinga, good question!
python check_please.py is run from the command line, the function is compiled then later execute when the variable
amount_due is assigned. That assignment calls the function with the two parameters defined by the variables
It’s possible to see the function run independently. If you were to start a REPL, you could try:
>>> from check_please import split_check #... interactive stuff like in the video >>> split_check(35, 5) 7
The “interactive stuff” is due to the module level code being exposed when importing the module. You’ll learn how to hide this code from imports using a special if statement in a later video. Not important for this question.
if __name__ == ‘__main__:’ idiom you might have seen elsewhere.
Post back if you need more help. Good luck!!!
Chris thanks for responding. I still think it does not make any sense how this function is running. This will not work in a local python environment, just in your REPL.