Multiple classes in a Python module

Here is a useful rule of thumb from what I have seen of typical Java projects:

The bottom-most package in Java should be a file in Python

What does that mean?
If your Java project was organized:

toplevel/
   subproject/
        Foo.java
        Bar.java
   subproject2/
        Baz.java
        Qux.java

Then your Python project should look like:

toplevel/
    subproject.py <-- put class Foo, Bar here
    subproject2.py <-- put class Baz, Qux here

Things to notice re: organization:

  • Do not use inner classes. Just put
    classes in the same module
  • By convention, things that start with _ are “private”
  • It’s OK to have “public variables”

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)