> __name__ == "__main__"
What makes this weirder than other languages detecting if they’re an import or an invoked file?
What makes this weirder than other languages detecting if they’re an import or an invoked file?
__this_file__ == “__launch_file__”
or similar. I understand python values “only one way” of doing things, but it would be helpful for readability.
if __main__:
There are no magic strings to remember and the IDE can help you look up variables.I honestly think one of the main reasons why python is so successful is as simple as:
print "Hello world!"
...and later: print("Hello world!")
It might not seem like much, but when you're asking someone to pick up a language outside of a classroom setting, it's just much more intuitive than: echo "Hello world!";
or: console.log("Hello world!");
or god forbid: public class GFG{
public static void main(String[] args) {
System.out.println("Hello world!");
}
}
These little things matter in the long run, even if they don't seem like they matter when you're already fluent.But Python breaking hello world in version 3 was crazy.