Skip to main content
Filter by
Sorted by
Tagged with
1 vote
2 answers
2k views

I recently wrote a code that had all attributes stored separately in different arrays like order_id = [] order_name = [] order_products = [] order_total = [] And when importing new orders through an ...
LukaJnk's user avatar
  • 13
0 votes
0 answers
68 views

I have the following tuple stored in a variable called newsfeed, which contains a row vector in the form of a CSR sparse matrix of shape (1, 9635) representing a news article and an integer from 0-4 (...
python_newbie's user avatar
1 vote
2 answers
231 views

I found out that it is possible to assign to class variables after class definitions and that methods are technically class variables. So I tried the following, which appeared to work. class Fruit(): ...
lamc's user avatar
  • 367
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 ...
Mukesh C's user avatar
  • 143
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): ...
piccio123's user avatar
1 vote
1 answer
66 views

So I just come across a function called super() that will call every parent's version of the function, but when I tried several different things there are things that i didn't quite understand. Here, ...
Hanzcerb's user avatar
0 votes
0 answers
24 views

class Library : def __init__(self,booklist) : self.permabooklist = booklist self.books = booklist sonipatlibrary = Library(["C++","Django","Flask&...
Ankur Dahiya's user avatar
-1 votes
3 answers
261 views

I'm new to Python and I'm working on a crawler project. I have a case want to ask you about good way to handle. For example. class Student: def __init__( self, user_id: str, name: str = ...
DFX Nguyễn's user avatar
1 vote
0 answers
97 views

I have a collection of ever more specialized classes which correspond to collections of the same kind of data (temperature, density, etc) but for different drifts, for example, one subclass has ...
Quixote's user avatar
  • 313
-1 votes
2 answers
949 views

I'm trying to learn object orientated programming and when setting an attribute why does it return None? Any tips on writing better code also appreciated... This is my class: BEANS = ["black"...
bbartling's user avatar
  • 3,564
0 votes
1 answer
4k views

I'm trying to set up an MQTT connector using a Python class. The problem I'm facing is that self.connected is always printed as False, even if in the on_connect module I've changed its value. Moreover,...
espogian's user avatar
  • 627
0 votes
2 answers
891 views

It might be dumb and repeat question just like Class-level read-only properties in Python, which is hard to understand and implement. But is there any simple way to stop object user to modify class ...
Leo Sam's user avatar
  • 83
0 votes
3 answers
76 views

I came by a code and wanted to get more understanding on when to use such arrangement. What would be a good scenario of not using __init__'s argument (name) in self? class ArgumentNotUsedInSelf: ...
marcin2x4's user avatar
  • 1,509
0 votes
3 answers
127 views

queue = [] goal_grid = { 1: [0, 0], 2: [0, 1], 3: [0, 2], 4: [1, 0], 5: [1, 1], 6: [1, 2], 7: [2, 0], 8: [2, 2] } sol = 0 visited = [] class State: def __init__(...
eme's user avatar
  • 17
0 votes
0 answers
78 views

I wanted to make a program which is CLI based login/register platform. I have made a version of this without using classes; file = open(r"database.txt","a+") def register(): ...
Lakshya Dubey's user avatar
3 votes
2 answers
2k views

Imagine I have a base and a derived class like so: class A: def foo(self): pass class B(A): def foo(self): pass I wish to wrap calls foo calls made by instances of B. ...
xrisk's user avatar
  • 3,918
0 votes
2 answers
125 views

I am learning how to use classes in python to alter some Keras methods to create various forms of Generative Adversarial Networks, GANs. In this case, I am trying to implement the gradient penalty ...
ScubaNinjaDog's user avatar
1 vote
0 answers
453 views

I would like to write a scraper that has 3 different "groups" of attributes (or data) that would [and likely should] be kept separately. I was hoping to use DataClasses and aim at Pythonic ...
Paul's user avatar
  • 555
0 votes
0 answers
39 views

I am simulating a person running with an enemy chasing the person. I am struggling in finding the code for the movement of the enemy. class Person (): def __init__(self, limits, name) self....
Richard's user avatar
0 votes
1 answer
281 views

So, I want the user to be able to use my program in English. They should be able to switch to their language via a dropdown-menu. My program has only four pages and a few labels on each, translating ...
Tom Orrow's user avatar
0 votes
2 answers
248 views

I'm trying to simulate a GUI as part of a larger card game, using python's tKinter. This GUI asks the user to enter a desired number of cards, press the deal button, and then it updates the buttons on ...
Amare's user avatar
  • 1
0 votes
1 answer
957 views

I have a basic understanding of usage of nodes, like node = node.next, and self.head, and things like node.next = self.head self.head = new_node to add whatever is in new_node to the beginning of the ...
hellwraiz's user avatar
  • 531
0 votes
1 answer
236 views

I am trying to pass a WX frame class to another class. I have three py files which are as follows: gui_20220510.py - this contains the gui code import wx class Frame_Demo(wx.Frame): def __init__(...
buggsbunny4's user avatar
0 votes
0 answers
56 views

Want to use class to make my code concise and easier to pass around to others. class distance: .05 = x .10 = y .15 = z ... I can't name something a number is there a way to get around ...
Nathaniel Wolff's user avatar
0 votes
0 answers
227 views

I have read, multiple times, that python passes arguments by value. However, I was testing the following simple code, and it looks like the class c objects are passed by reference (a modification ...
user18170958's user avatar

1 2 3
4
5
11