All Questions
33 questions
-2
votes
1
answer
294
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 ...
2
votes
1
answer
1k
views
In Python when is absolutely preferable to use a class instead of a module?
Python is the language I use most in this period.
My background in Java
Before start learning Python I have programmed in Java language. In Java all code is written inside the methods of a class and ...
2
votes
3
answers
189
views
Which association should be in the class diagram
there are a vehicle class and customer class . In short, in the customer class there is a function that shows 'can this person or company rent that car'.The function uses a object of vehicle and ...
3
votes
2
answers
464
views
Accessing properties from embedded objects as attributes of container class
In Python, I have a class C which embeds objects from classes A and B. Is it considered good practice to creates shortcuts from the properties of embedded objects of classes A and B as attributes of ...
1
vote
1
answer
510
views
Creating an attribute of an object versus a method in the class
This question pertains to properly structuring a class. The object of a class I have is instantiated with multiple parameters. Many of these parameters are then manipulated with each other to derive ...
2
votes
0
answers
34
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 = {}
...
0
votes
2
answers
460
views
Dynamically choose whether to use __slots__ in a class
I've got a generic container class:
from typing import Container, Generic, TypeVar, NamedTuple
import sys
fixed_typing = (sys.version_info >= (3, 6, 2) or
(3, 5, 3) <= sys....
3
votes
2
answers
1k
views
Is “A programmer-defined type.” a right definition of "class" in Python?
In Think Python 2e "class" is defined as "A programmer-defined type. A class definition creates a new class object."
But isn't a built-in type considered a class too?
Using Python 3.4.0, the ...
0
votes
1
answer
3k
views
Instantiate a class from a config file. Where should the parse function go?
I have a class in python that is instantiated from the values of a (json) config file. I was wondering what is the best practise to do that (if there is a best practise and is not just a matter of ...
1
vote
3
answers
235
views
Everthing in a class/classes or just part of the program?
I wanted to move my program into a class or classes because most of the form post I read say it makes the program easier to read, understand the flow of the code, and improve maintainability.
...
0
votes
2
answers
159
views
Using a class for a collection element, with methods to access other collections
I'm hoping for a sanity check in my design thinking.
I'm working with a small team on a website based on a MongoDB database. There are several collections in the DB -- for example, one representing ...
-1
votes
1
answer
153
views
Memory override using classes when using lists in python
I am trying to create a new variable with class Lamb (called hold) using a variable (main), which also has class Lamb. Lamb has two parameters (x and y).
I create a variable called main with class ...
29
votes
2
answers
73k
views
Classes vs. modules in Python
Python has many modules (such as re) that perform a specific set of actions. You can call the functions of this module and get results, and the module as a whole has an idea behind it (in this case, ...
0
votes
3
answers
2k
views
When NOT to use a class / member variable?
I am trying to learn WHEN NOT to use:
classes
member variables
HERE IS THE CODE
access_point_detection_classes.py
from scapy.all import *
class Handler :
def __init__(self) :
self....
7
votes
1
answer
20k
views
Is calling the superclass constructor in a subclass really important?
The following piece of Python code uses a superclass solely as the repository of functions that one of more subclasses may draw from:
class Class(object):
''' A trivial repository for functions ...