Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
3 votes
1 answer
537 views

Object-oriented programming design with relational database tables

I want to understand what is considered best-practice to better align with OOP when handling relational databases. I cannot find any online examples where classes and a more maintainable/re-usable ...
Yannis's user avatar
  • 147
-2 votes
1 answer
435 views

Defining functions inside vs outside a class

Say I have a class with a function do_thing that is comprised of multiple steps, which themselves segregate into functions (first_process and second_process). At what point would this be considered ...
Tim Kirkwood's user avatar
2 votes
2 answers
952 views

Splitting up large SQLAlchemy model

Anybody have advice on splitting up a large SQLAlchemy model into smaller parts? I have a ~2000 line model called Article that is becoming difficult to manage. We often have to scroll and scroll to ...
caseym's user avatar
  • 129
2 votes
2 answers
2k views

Why access the attributes of a Python class by reference?

Attribute references and instantiation In this link, that is part of the official Python documentation, I have found the following information: Class objects support two kinds of operations: ...
User051209's user avatar
0 votes
1 answer
634 views

How to handle root paths in a custom package?

I am writing a custom python package, which produces some files in a certain directory. This directory I call root_path and should be set by the user. So basically, it should be a conf variable but ...
Corram's user avatar
  • 103
3 votes
3 answers
330 views

Referencing transient class attributes

I've just started dipping my feet into OOP. Is it considered bad practice to have classes that reference attributes that depend on another function being called and thus may not exist (version 1)? I'...
Tim Kirkwood's user avatar
0 votes
1 answer
997 views

Dependency Injection for dynamic objects

I am learning about Dependency Injection and I have been recently implementing the following classes for an app that executes commands over ssh using Python. I am confused about whether I am using it ...
Florentin Alexandru Iftimie's user avatar
-1 votes
1 answer
3k views

Calling helper functions in a Python `__init__` function

Problem I am currently working with a class that necessarily has a very complicated initialization function (>350 lines of code) given that many computations and attributes need to be performed and ...
WhoDatBoy's user avatar
  • 123
-1 votes
2 answers
3k views

Initializing instance variables from json file

I have a class whose instance variables should be initialized from a file ('settings.json'). That file does not always exist or is sometimes not filled with useful values, so I have to check for that ...
user69188's user avatar
-3 votes
1 answer
71 views

Should I design a class to handle my other class or the attribute of my other class?

Please allow me to illustrate my question with a simple example. Let's suppose we have a Customer class: class Customer: def __init__(self, name, surname, email): self.name = name ...
multigoodverse's user avatar
2 votes
0 answers
35 views

Update class member gradually [duplicate]

Consider the following: import typing class MyClass(object): def __init__(self): self.my_member: typing.Optional[dict] = None def update_member(self): self.my_member = {} ...
Jimmy Thrasibule's user avatar
0 votes
0 answers
118 views

"Best practice" or "design pattern" to group a class with "associated" classes in an object-oriented language

Sometimes a class A can have an "associated" class B such that the implementation of B depends on the implementation of A. For example, this can happen when B's objects are to be created by A's ...
Alexey's user avatar
  • 958
2 votes
2 answers
4k views

Module with globals or Class with attributes?

Currently I'm working with a lot of modules where the original developers used global variables to control states and to exchange important information between functions, like so: STATE_VAR = 0 def ...
Andrei's user avatar
  • 131
2 votes
0 answers
97 views

Is assigning a method in the constructor good practice? [closed]

Here's a class with a method that calls different functions based on a parameter set in the constructor: functions = { "arg1": f1, "arg2": f2, "arg3": f3 } class C: def __init__(self,...
Hey's user avatar
  • 159
0 votes
2 answers
2k views

"private methods" vs method out of class in a python module

I have a module with the class Foo. Foo has three methods: The constructor(__init__()) An error handling method (_error_handler()) The method that actually does something. (run()) Then, I have a bunch ...
user avatar

15 30 50 per page