510 questions
2
votes
0
answers
66
views
New Dialog Class Incorrect Button Style
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 ...
1
vote
0
answers
104
views
Exclude methods consisting of a single pass statement from coverage reports in python
In my class, I have some methods that can be overridden by subclasses, but do not need to be.
I like to test my project and generate a coverage report using coverage.py.
Because the method of the ...
2
votes
1
answer
267
views
Return a different class based on an optional flag in the arguments without factory
I am implementing a series of classes in Equinox to enable taking derivatives with respect to the class parameters. Most of the time, the user will be instantiating class A and using the fn function ...
1
vote
1
answer
44
views
Adding a second class breaks tkinter variable
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 ...
1
vote
1
answer
62
views
How to inherit (from a parent class) dataclass field introspection functionality?
I have a parent dataclass, and various other classes will then extend this parent dataclass. Let's call these dataclasses DCs. In the example code below, see ParentDC, and an example ChildDC:
from ...
0
votes
2
answers
67
views
Python decorators with class methods
I want a decorator that I can use as both @decorator and decorator() with class methods, like this :
def decorator_with_args(name):
print(f'Hello {name} !')
def decorator(func):
def ...
1
vote
3
answers
84
views
How to display an image with classes in tkinter?
import tkinter as tk
from PIL import ImageTk, Image
window = tk.Tk()
window.geometry("300x300")
canvas = tk.Canvas(window, width=300, height=300,bg="red")
canvas.pack()
class ...
0
votes
1
answer
40
views
How can I substitute an imported python class in a .py file without modifying the file itself?
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
...
-1
votes
1
answer
101
views
How to add class variable values to a list, python 3x?
I'm trying to add class variable values to a list inside a function, but I'm not seeing any errors or the expected output? The comboxbox doesn't display when I uncomment the list code.
Outside of the ...
0
votes
3
answers
123
views
How to run multiple instances of an object with two threads inside each object?
I'm trying to wrap two threaded functions inside an object and run a couple of instances of the object. So far I could only run the objects if I pull the threading outside the class.
import threading
...
1
vote
2
answers
131
views
On demand Python imports
I have the following situation: A module that contains a class Foo with some additional convenience functions for assembling Foo objects. A Foo object contains methods for interacting with data in an ...
4
votes
3
answers
238
views
How to correctly define a classmethod that accesses a value of a mangled child attribute?
In Python, how do I correctly define a classmethod of a parent class that references an attribute of a child class?
from enum import Enum
class LabelledEnum(Enum):
@classmethod
def list_labels(...
0
votes
0
answers
241
views
ValueError: Attempt to convert a value (class) with an unsupported type (class) to a Tensor
these codes were running flawlessly on tensorflow==2.15, for the purpose of GPU acceleration, I switched to tensorflow-gpu == 2.10.1 with keras 2.10, respectively. and this ValueError raised up on my ...
0
votes
0
answers
41
views
Updating class attributes in python
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
How is class Franchise, linked with Class Menu? in Below Python Code?
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
Error while using a custom class in Python: 'AttributeError: 'module' object has no attribute 'MyClass
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 ...
0
votes
0
answers
27
views
In python class, how to pass returned value of a method of a class as input to another method of the same class
I am using boto3 library to establish connection to an s3 compatible storage. I had created a class with constructor that take cluster details, access key & IDs as inputs, having these initiated. ...
-2
votes
2
answers
118
views
Why are these 2 python class instance could equal to each other?
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
0
answers
33
views
how I can describe that my function return (or need) a object with same type that the class I'm building? [duplicate]
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
2
answers
867
views
Decorate all functions of a Python class while being able to access the class attributes within the decorator
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 ...
0
votes
2
answers
48
views
Turtle doing nothing in embedded Tkinter window
I am trying to make a program in which you can draw different shapes. I already managed to embed the turtlescreen into my already existing Tkinter one (root) and got a Tkinter Menu, in which I can run ...
0
votes
1
answer
155
views
DataFlow Code returning empty output for DoFn class
I am trying to run the below code using dataflow, where I have 2-3 functions defined inside a class, out of which 2 functions are working but the send_email() is working nor throwing any errors.
...
-1
votes
1
answer
75
views
I developed a class for generating images, but I have a type problem (name 'train_step' is not defined) that I can't
Here's the complete class code with an example of its implementation.
import tensorflow as tf
import numpy as np
import time
from tensorflow.keras.applications.inception_v3 import InceptionV3
from ...
2
votes
1
answer
2k
views
Method for correct/pythonic way to use @cached_property to set a permanent attribute on a Python class
I am trying to set a permanent attribute on a class to be used by other methods throughout the life of the instance of the class
class Test:
@cached_property
def datafile_num_rows(self) -> ...
1
vote
2
answers
212
views
Python - pass arguments when adding a button to plot's toolbar (matplotlib)
I am trying to add a button to toolbar. The button is a custom class that inherits ToolToggleBase. In my custom SelectButton class, I want to pass few arguments, but I getting an error:
import numpy ...