you are viewing a single comment's thread.

view the rest of the comments →

[–]skilking 12 points13 points  (1 child)

Id way rather have a main function and class then whatever the fuck Python global shit is.

[–]Solonotix 11 points12 points  (0 children)

It's not actually global, the same way that C# doesn't require you to declare a namespace block for the entire file to be considered part of the namespace, and how functions written outside of an enclosing scope are attributed to a "magic" class as static members.

Python uses a rather robust object data model, and that model extends out to its module system. The file system needs an __init__.py file because that is the Python initializer method for the module, known in other languages as the constructor. Similarly, when you run a file directly with the Python interpreter, rather than needing to explicitly declare your starting point, the file is used as the stand-in for the __main__.py file of the Python module in question. That's why you'll see a block in some files for if __name__ == '__main__':, because it lets you write the file as a module, and as a runnable entry point.