Skip to main content
Filter by
Sorted by
Tagged with
1407 votes
17 answers
574k views

In Programming Python, Mark Lutz mentions the term mixin. I am from a C/C++/C# background and I have not heard the term before. What is a mixin? Reading between the lines of this example (which I have ...
2 votes
0 answers
66 views

I was trying to make a subclass that acts like the original but its go function returned the string of the text of the button, instead of the index of the button. My own defined subclass makes the ...
0 votes
1 answer
1k views

I want to use the Python library fpdf2 and build my own class to generate a pdf document. I tried this: from fpdf import FPDF class MyPdf(FPDF): def __init__(self, *args, **kwargs): ...
0 votes
0 answers
36 views

Consider the following code, if you will: class ParentService: BASE_DIR = '/some/path' class Results(str, Enum): RESULT1 = 'ResultOne.xlsx' RESULT2 = 'ResultTwo.pdf' ...
0 votes
2 answers
867 views

I've got a class and would like to apply a decorator to all functions within that class without having to add a function decorator to every single function. I know that there are solutions like the ...
1 vote
1 answer
44 views

I have a class for a GUI with two radio buttons one to set save_to_excel to True and the other to False. However I wanted to add a loading screen using threading, but when I add that second class the ...
0 votes
0 answers
33 views

I'm have an unexpected problem. This is a random example, but describe the problem it self. With this code: class Location: def __init__(self, name: str) -> None: self.name = name ...
0 votes
1 answer
57 views

First up, I'm really pretty bad at OOP and tkinter/customtkinter and this is only my third project I've built with classes over straight functions, so please excuse my mess. I'm getting there, and ...
0 votes
0 answers
34 views

import tkinter as tk import math,time,random from PIL import ImageTk, Image,ImageEnhance start_time = time.time() window = tk.Tk() window.geometry("300x300") canvas = tk.Canvas(window, ...
0 votes
0 answers
5k views

How do I create a one-to-many relationship in a Flask SQLAlchemy database? My db class: class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String, ...
0 votes
1 answer
40 views

What I'd like to achieve is: b.py(might be in a third party package I cannot modify): from xxx import A class B: def __init__(): self.a = A() The file I actually execute: execute.py ...
100 votes
7 answers
43k views

I always use FBVs (Function Based Views) when creating a django app because it's very easy to handle. But most developers said that it's better to use CBVs (Class Based Views) and use only FBVs if it ...
0 votes
0 answers
41 views

I'm not an expert python programmer. After some time and effort I've built a tkinter UI that properly works. Recently, I've found myself needing to add a scrollbar inside the frame, since I need to ...
0 votes
2 answers
926 views

Is there an elegant way to list all properties defined on a Pydantic BaseModel? It's possible to extract the list of fields via BaseModel.model_fields and the list of computed fields via BaseModel....
0 votes
1 answer
165 views

New to python and trying to create an app with customtkinter. The app lets users pick values from different drop-downs and generates codes based on the chosen value. Updated per comment from Mike-SMT: ...
2 votes
1 answer
44 views

Defining a class of instance variable from commonly used fields in API response by looping through each JSON record self.id=response['identifier'] -->output: 1234 self.name=response['...
1 vote
1 answer
160 views

I am trying to run a simple code in ROS to create a subscriber and a publisher using classes in python. I am new to using classes in python and I am not sure what I am doing wrong here. Below is the ...
0 votes
0 answers
41 views

I have two classes Player and LineUp, one is used within the other (shown below). I am trying to update my LineUp class after I have already instantiated it. class Player: def __init__(self, ...
0 votes
1 answer
48 views

What informs the code that The relationship between the Franchise and Menu classes is that The Franchise class has an attribute menus that stores instances of the Menu class, when clearly Menu and ...
0 votes
1 answer
555 views

I'm facing an issue while working with a custom class in Python. I have a module named 'my_module' with a class called 'MyClass'. However, when I try to instantiate the class in another script or ...
-2 votes
1 answer
476 views

The problem is although i can see the method I'm calling, the error says I don't have a method the way I call. Here is the error: Traceback (most recent call last): File "C:\Users\htuna\...
12 votes
2 answers
5k views

@dataclass class Stock: symbol: str price: float = get_price(symbol) Can a dataclass attribute access to the other one? In the above example, one can create a Stock by providing a symbol and ...
-2 votes
2 answers
118 views

from dataclasses import dataclass @dataclass class ThreeDPoint: x: int | float y = 0.0 z: int | float = 0.0 point_1 = ThreeDPoint(1.0,2) point_3 = ThreeDPoint(1,2) print(point_1 == ...
0 votes
1 answer
72 views

I'm programing a Black Jack game in a Jupyter notebook and for that I have a "player" and a "dealer" class and also a function (BlackJack()) which basically runs the entire game. def BlackJack(): ...
5 votes
3 answers
4k views

class Something: def __init__(self, ...): ... def update(self): ... def add_update(self, func): def fct(*args, **kwargs): self.update() func(*args,...

1
2 3 4 5
11