Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
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 ...
Randumb_ASH's user avatar
-1 votes
1 answer
64 views

Using .get() from an entry in tkinter within a class

I am trying to get the entered value from an entry widget to record in a text file, I've tried a lot but am not sure where to go from here. It come up with this Error: Exception in Tkinter callback ...
user30428193's user avatar
1 vote
0 answers
103 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 ...
502E532E's user avatar
  • 581
0 votes
0 answers
36 views

Accessing a sibling inner class in initialiser

Consider the following code, if you will: class ParentService: BASE_DIR = '/some/path' class Results(str, Enum): RESULT1 = 'ResultOne.xlsx' RESULT2 = 'ResultTwo.pdf' ...
zkvvoob's user avatar
  • 496
2 votes
1 answer
266 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 ...
JamesVR's user avatar
  • 173
-2 votes
2 answers
60 views

discord.ext.commands.errors.CommandNotFound: Command "coucou" is not found

I'm trying to create a bot Discord with Python. I created a class MyBot like this: import discord from discord.ext import commands intents = discord.Intents.all() intents.members = True class MyBot(...
Toniixav's user avatar
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 ...
usherא's user avatar
  • 21
0 votes
1 answer
43 views

I wrote the code for this analog clock, but I don't know why place of the numbers are not correct

import pygame from math import radians, sin, cos from datetime import datetime class Clock: def __init__(self): self.width, self.height = 800, 800 self.white = (255, 255, 255) ...
Mohamad Homaei's user avatar
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 ...
bzm3r's user avatar
  • 4,664
0 votes
1 answer
56 views

Trying to center and uniformly space a 4x4 grid of entry widgets within a frame, within a frame class. What am I missing?

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 ...
nannerpuss's user avatar
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 ...
Prasun Kumar Khan's user avatar
0 votes
0 answers
34 views

Having a problem with calling the class twice

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, ...
MeHocha 333's user avatar
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 ...
MeHocha 333's user avatar
0 votes
0 answers
354 views

OpenAI API upgrade from 0.28 to 1.x

I am trying to upgrade the OpenAI 0.28 version to 1.2.2. For doing that I defined the client and replaced the openai chatcompletion with client. Below is the constant file which will be used in the ...
Pushpendra Singh's user avatar
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 ...
Feephy's user avatar
  • 143
0 votes
3 answers
59 views

For class created from Python turtle module, instead of return functions at each method, how can data created from a method be used in different one?

For a class (snake class) created from the turtle module in Python: Problem 1. when the move() method is called, the snake segments are moving backwards instead of forward . The problem seems to be ...
chris's user avatar
  • 23
-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 ...
James-Jesse Drinkard's user avatar
0 votes
0 answers
41 views

Unable to properly initialize a tkinter scrollbar inside a UI

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 ...
Elia Melloni's user avatar
0 votes
3 answers
122 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 ...
R.Orteza's user avatar
0 votes
2 answers
925 views

List all properties defined on a Pydantic BaseModel

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....
SultanOrazbayev's user avatar
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 ...
Ash's user avatar
  • 205
0 votes
1 answer
165 views

Programatically create multiple instances of CustomTkinter Combobox Python

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: ...
Gautam's user avatar
  • 2,763
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(...
SultanOrazbayev's user avatar
2 votes
1 answer
44 views

Python convert class instance variable to nested structure

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['...
Victor's user avatar
  • 23
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 ...
pepCoder's user avatar
  • 329
1 vote
1 answer
159 views

ROS (Robot Operating System) simple publisher and subscriber using class in python

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 ...
Sabyasachi's user avatar
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, ...
PureSlurp's user avatar
0 votes
2 answers
67 views

How can I retain a reference to the parent object when creating an instance of a nested class through the outer object in Python?

Is it possible to retain a reference to the parent object when creating an instance of a nested class through the outer object, without explicitly passing the parent object as an argument? class ...
Japan Manul's user avatar
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 ...
Joseph Matheri's user avatar
0 votes
1 answer
68 views

Quit Tkinter application by calling class method

I am trying to build a splash screen that I will be able to call from an external application using Tkinter. I'd like to define my GUI in a class, like this: class Splash: def __init__(self): ...
Ben Zelnick's user avatar
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 ...
Albin Siby's user avatar
-2 votes
1 answer
475 views

Python Selenium AttributeError: object has no attribute

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\...
Selim's user avatar
  • 1
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. ...
vpothurajula's user avatar
0 votes
1 answer
74 views

Understanding this class intialization in python

I have this piece of code, part of a Spikingjelly neural network training functionality, which gets some errors on this line after running. I'm not quite experienced in Python, and I don't understand ...
Marziye Hasanshahi's user avatar
-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 == ...
anonNEWlearner's user avatar
0 votes
1 answer
58 views

A script changes the source code of class. Why can the effect not be observed in the same console or test, where the script was run?

I have written a script, that automatically adds a property to a class. It works, but currently I can not test it. The code is shown below, but can also be seen on GitHub. See the class Cat, the ...
Watchduck's user avatar
  • 1,209
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 ...
Miguel A. Díaz Castillo's user avatar
0 votes
1 answer
672 views

Automatically calling class function after init

I want to automate a class method which would be called right after __init__ has completed. e.g, class A: def __init__(self): initialization statement def post_init(self): #...
atskdev's user avatar
0 votes
2 answers
865 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 ...
Strawbert's user avatar
-1 votes
2 answers
133 views

Struggling with class methods, cls, and self when using functions cross classes in python while updating a dictionary

I am trying to build a small UI for updating some settings and then displaying some intake data on a raspberrypi. Python version is 3.9.2. The most logical way to save the settings I thought would be ...
Shenanigator's user avatar
  • 1,086
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 ...
Akemi's user avatar
  • 1
1 vote
1 answer
137 views

Python overload __setitem__ does not replace self out of the class range

I am trying to create a kind of dataframe subclass with inheritance of polars.DataFrame. I would like to modify the __setitem__ method to make following statement possible: df['test_column'] = 'test' ...
KYPcode's user avatar
  • 81
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. ...
Sandeep Mohanty's user avatar
0 votes
3 answers
125 views

What is the logic of changing class variables?

The following code was supposed to clarify how Python class variables behave,but somehow it opens more questions than it solves. The class Bodyguard has the variable protect, which is a list that by ...
Watchduck's user avatar
  • 1,209
-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 ...
fares rs's user avatar
0 votes
0 answers
76 views

Tkinter result page with possible cyclic dependency

I'm having trouble creating a results page for a tkinter GUI that I've made. The problem is that the page2 file has to import the page3 file in order to go to page3 when clicked with a button. In the ...
JimV's user avatar
  • 11
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) -> ...
metersk's user avatar
  • 12.7k
0 votes
1 answer
51 views

Merge private attributes in Python

I know that private attributes are loosely defined in Python, but I'm trying to figure out what would be the most lean way of implementing a method to merge together private attributes. Class Event: ...
unitrium's user avatar
1 vote
2 answers
207 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 ...
Alon123's user avatar
  • 174
1 vote
1 answer
1k views

Pandas "DataFrame"s as class properties. How should I initialize them in class constructor __init__()?

I have a class which will manage multiple pandas Data Frames. The Data frames are class properties. I have initiated every Data Frame in the class constructor and assigned an empty Data Frame to them (...
Diaco's user avatar
  • 38

1
2 3 4 5
11