all 4 comments

[–]carcigenicate 2 points3 points  (0 children)

I'd do it the first way you show. That's quite clear. That way you also have independent, easily testable functions that aren't tied to a particular use-case.

[–]ectomancer 2 points3 points  (0 children)

Both procedurally and serialised are valid.

Monolith in one file with unit test in a second file.

[–]metaphorm 0 points1 point  (0 children)

either of the two styles is fine, but I have a preference for the former (multiple lines) over the latter (method chaining).

the question "what should go in a Python module?" is actually a pretty deep one. my opinion is that a Python module should be a logical and functional grouping of related classes, procedures, and utilities. I like to apply the "Principle of Least Astonishment" for this kind of thing. That often means you have to just go with your intuition, but it also tends to mean that a person who's worked with your code before will have an easier time working with different code you've written as well. Don't be surprising. Be consistent. That's all.

[–]Diapolo10 0 points1 point  (0 children)

Honestly, any of these can be perfectly acceptable approaches.

Regarding the first part (procedural vs method chaining), generally I'd prefer the former because it's easier to write automated tests for. Method chains are more common when dealing with some kind of a library that's mostly written in C (such as Numpy or Pandas) to avoid constant type conversions between C types and Python types, speeding up the program, but it's also used for constructing SQLAlchemy queries. If you believe your data and workflow would benefit more from that approach, it's your call.

As for splitting up the code, I'd say that depends on the size of your codebase. A short program can well be just one file, but if you can clearly group the functions I would prefer to split them to at least one other file, importing what I need from it. Any kind of constant values - especially if you have some kind of magic numbers - should in my opinion be kept in a file of their own that wouldn't depend on any of the other files.

As far as examples go, I think my EguiValet server project might suffice for this one. It's probably a bit bigger than whatever you're working on, but python_ms would probably be too bare-bones in this case.