Ryan Ryan - 13 days ago 6
Python Question

Python namespaced class module directory layout

I want to create a

User
module which is namespaced
example
, and currently use the directory structure

example\__init__.py (Empty file)
example\user.py (Define the class `User`)


And in other file I import via

from example.user import User


It works, but I want to double check if it is the the Pythonic Way to do it.

Answer

Ryan,

Your approach is good and 100% Pythonic. Just make sure that you have proper comments in the modules you make.

You can refer this link for more information.

Comments