In cherryPy for example, there are files like:
__init__.py_cptools.py
How are they different? What does this mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
__...__means reserved Python name (both in filenames and in other names). You shouldn’t invent your own names using the double-underscore notation; and if you use existing, they have special functionality.In this particular example,
__init__.pydefines the ‘main’ unit for a package; it also causes Python to treat the specific directory as a package. It is the unit that will be used when you callimport cherryPy(andcherryPyis a directory). This is briefly explained in the Modules tutorial.Another example is the
__eq__method which provides equality comparison for a class. You are allowed to call those methods directly (and you use them implicitly when you use the==operator, for example); however, newer Python versions may define more such methods and thus you shouldn’t invent your own__-names because they might then collide. You can find quite a detailed list of such methods in Data model docs._...is often used as ‘internal’ name. For example, modules starting with_shouldn’t be used directly; similarly, methods with_are supposedly-private and so on. It’s just a convention but you should respect it.