0

I have a project in which I have a lot of methods in a class. Currently all methods are directly in the file where the BaseProfle Class is defined. We wanted to move them into own files to make it easier for new team members.

The following code blocks show our idea of doing it. But we aren't sure if there is a more pythonic way to do.

# __init__.py
from .request import url_formatter, request
...

class BaseProfile:
    url_formatter = url_formatter
    request = request
    ...
# request.py
def request(self: BaseProfile, body):
...
leona
  • 423
  • 3
  • 16

1 Answers1

0

By convention, class definitions in python occupy a single file. IMHO, the best way to keep BaseProfile readable is to keep its methods short.

If really want to spread the class definition across multiple files, you could consider this approach of putting the import statements directly inside the class definition. In my opinion this is cleaner because it removes the need to assign url_formatter = url_formatter etc inside the class definition.

Another way is to use mixins (see here, referred to by this answer).

Emerson Harkin
  • 889
  • 5
  • 13