Python File Structure on GitHub
python
Solution
The `setup.py` is part of Python’s module distribution using the distrubution utilities. It allows for easy installation of the Python module and is useful when, well, you want to distribute your project as a whole Python module.
The `__init__.py` is used for Python’s package system. An empty file is usually enough to make Python recognize the directory it is in as a package, but you can also define different things in it.
Finally, the `__name__ == '__main__'` check is to ensure that the current script is run directly (e.g. from the command line) and it is not just imported into some other script. During a Python script execution only a single module’s `__name__` property will be equal to `__main__`. See also my answer here or the more general question on that topic.
Problem
I've been looking around at some open source projects on Python, and I'm seeing a lot of files and patterns that I'm not familiar with. First of all, a lot of projects just have a file called `setup.py`, which usually contains one function: ``` setup(blah, blah, blah) ``` Second, a lot contain a file that is simply called `__init__.py` and contains next to no information. Third, some `.py` files contain a statement similar to this: ``` if __name__ == "__main__" ``` Finally, I'm wondering if there are any "best practices" for dividing Python files up in a git repository. With Java, the idea of file division comes pretty naturally because of the class structure. With Python, many scripts have no classes at all, and sometimes a program will have OOP aspects, but a class by class division does not make that much sense. Is it just "whatever makes the code the most readable," or are there some guidelines somewhere about this?