All Questions
28
questions
0
votes
1answer
44 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
0answers
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
2answers
395 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....
2
votes
2answers
911 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
1answer
833 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
3answers
141 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
2answers
119 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
1answer
135 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 ...
25
votes
2answers
62k 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
3answers
834 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....
5
votes
1answer
18k 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 ...
4
votes
1answer
807 views
Avoiding tightly coupled class definitions in Python for has-a relationships
I have the following code:
class Car(object):
def __init__(self, my_id):
self.my_id = my_id
self.color = color
self.brand = brand
self.get_color()
self....
1
vote
1answer
125 views
Is this the right way to use classes on this project?
Before any down voting or blaming, please bear in mind that this is my first "serious" Python project. Before this I have only coded a program that uses several Google API's to do stuff, and not much ...
2
votes
2answers
1k views
python - differences between reusable code vs. code for solving specific tasks
Reusable code (ex. libraries and frameworks) and code written to solve a specific task and not meant to be reused as a general tool (for example, code being used only by my 6 person team in a private ...
-1
votes
3answers
166 views
Python — Class and Object [closed]
I got a question that quite disturbs me a lot and I think it might help a lot if I had an answer to it. So I got this:
class Klasse1:
variable1 = "haha"
class Klasse2:
variable2 = "hoho"
...
2
votes
3answers
5k views
What is the difference between proxy class and delegation in Python?
Wiki:
A proxy, in its most general form, is a class functioning as an interface to something else. The proxy could interface to anything: a network connection, a large object in memory, a file, or ...
2
votes
2answers
2k views
Is it OK to use (WTF) forms to validate against stuff from DB?
Form classes are intended (IMO) for submitted data against rules. For example: are passwords equal, is end date later than start date.
submitted data--->|Form|
Is it okay for Form classes to ...
3
votes
1answer
73 views
Should I be taking these as arguments or define them in a sub class?
So I am making a mario clone in pygame and I have a base class Character and two sub classes, Mario and Luigi. The methods that the Character class defines require a significant amount of attributes ...
2
votes
1answer
423 views
Python Classes and Design Questions
What is the best way to design a class to see if an update occurs on a property?
I have a whole bunch of classes, and current am going through a re-design of the python package I created. ...
0
votes
1answer
1k views
Setting up folders and importing modules in Python
I'm building an app to automate some processes that are annoying to do by hand (looking in a file, taking certain information out of a file, building another file with that information).
My project ...
1
vote
1answer
1k views
Splitting single Class into multiple Classes
I am writing automated test scripts with Selenium Webdriver (Python) and I try to follow the correct programming practices, specifically the Object Oriented methodologies, where possible.
At the ...
4
votes
2answers
611 views
In Python, is there any difference (apart from a few listed exceptions) between classes and dictionaries?
My logic goes like this:
def A(val):
return {'a':val}
print(A(7)['a'])
is the same as
class A:
def __init__(self, val):
self.a = val
print(A(7).a)
Obviously, there are problems ...
2
votes
1answer
4k views
Using class like an object in Python
I am learning from Learn Python the hard way where I have come across a study drill where they want to know that whether a class can be used like an object.
As I have experimented:
class A(object):
...
1
vote
1answer
3k views
Dynamic method creation in python
I have a class that will have a number of external methods that will all call the same smaller set of internal methods. So something like:
obj.method_one(a, c) and
obj.method_two(a, c)
where obj....
22
votes
1answer
47k views
Why use classes when programming a tkinter gui in python
I program primarily in python and have programmed a couple of GUI's with Tkinter, every tutorial I have ever seen has recommended defining and using a class for the GUI, but my GUI runs flawlessly ...
11
votes
1answer
11k views
When to use private methods in Python
I have a class, but every method in it should be private (apart form __init__ and __str__). Should I denote every method with a double underscore, or is that deemed bad practice?
8
votes
2answers
4k views
Should I split a Python class with many methods into multiple classes?
I have a class that will end up having more than ~30 methods. They all make sense to be part of the same class because they require access to the same data.
However, does it make any sense to split ...
8
votes
5answers
2k views
Python: What is the point of using “import”?
I am not very clear on this aspect. Let's say you have a bunch of .py files that are their own separate modules.
Why does each .py file need to import the others when they use that class? Or do they? ...