Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Conditional Check

mohan Abdul
PLUS
mohan Abdul
Courses Plus Student 1,453 Points

how does second_app.py get the dunder name '''app''' when the instructor did not type the script? @ approx 3 min 39 sec

how does second_app.py get the dunder name '''app''' when the instructor did not type it in the script? (@ approx 3 min 39 sec of the video). How did python get '''app''' dunder name for the second one?

2 Answers

Steven Parker
Steven Parker
231,271 Points

The value of "__name__" is set by the system. In the main program, the value of it is "__main__". But inside a module that was loaded using "import", the value of it is the name of the module that was imported. In the video example, that happens to be "app" (because the file is "app.py").

mohan Abdul
PLUS
mohan Abdul
Courses Plus Student 1,453 Points

Steven Parker ("But inside a module that was loaded using "import", the value of it is the name of the module that was imported." ) Ok if i am to paraphrase this in a nut shell to make sure i understand the ''second_app'' inherit the file name from the imported one?

Steven Parker
Steven Parker
231,271 Points

This is not an example of inheritance, and "second_app" is the main program in the video example.

It's "app" that was imported, and has "__name__" equal to "app".

mohan Abdul
mohan Abdul
Courses Plus Student 1,453 Points

Steven Parker, so did ''second_app'' get its name from ''import app'' or the file name ''app.py''?

Steven Parker
Steven Parker
231,271 Points

The value of "__name__" is never shown from 'second_app', it's only displayed by the code in 'app'.

When the code in 'app" runs, it displays it as "app", since that's the module it was included from.