I'm exploring Python and how to structure code.
Consider the following project structure
<project root>/controllers/user_controller.py
This file then contains
class UserController:
def index():
# Something
When importing this from outside, it ends up as
import controllers.user_controller
controller_instance = controllers.user_controller.UserController()
As a Ruby developer, it feels more natural to do controllers.UserController()
or just UserController()
if the controllers folder was part of the load path, like in Rails.
Is there a (clean) way to omit the package name? I know I can do from controllers.user_controller import UserController
, but I honestly don't fancy the verbosity.
I would like to have one python file per class, but I don't want a new module for each class.
import controllers.user_controller as ctrl
?