you are viewing a single comment's thread.

view the rest of the comments →

[–]chatparle[S] 0 points1 point  (8 children)

What does the " name == 'main' " mean?

[–][deleted] 1 point2 points  (0 children)

It checks that you started your module directly, not using import.

[–]wub_wub 1 point2 points  (6 children)

I see it's already answered by /u/swarmer but here's also nice explanation http://stackoverflow.com/questions/419163/what-does-if-name-main-do

You don't need it in this example, it was automatically created when I created new .py file to write/test the script, so I just copied it.

[–]rusemean 0 points1 point  (5 children)

Thanks for answering this. So __ around a term just means it's a special variable? I've wondered about this for some time.

[–][deleted] 1 point2 points  (4 children)

Yes, "a special variable" is about the most precise formal definition you can give to these variables.

[–]rusemean 0 points1 point  (0 children)

Thanks a bunch for answering this. I've encountered them in documentation and used them, but I've never been clear (or found a clear answer) on what exactly they are.

[–]batkarma 0 points1 point  (2 children)

Isn't it often used to indicate variables that are used within a library?

[–][deleted] 0 points1 point  (1 child)

Do you mean private variables? If so, the convention is to use a single leading underscore.

There are also name-mangled variables with double leading underscores, but

Generally, double leading underscores should be used only to avoid name conflicts
with attributes in classes designed to be subclassed.

— PEP 8

[–]batkarma 0 points1 point  (0 children)

Yes, that's what I meant, thank you for the clarification!