class

Pandas dataframe showing ValueError with class

Pandas dataframe showing ValueError with class Question: I am trying to make a Dataframe inside a class called CaptainAmerica. I am trying to implement the values using the finalStats variable. I was expecting output until I ran into this error: raise ValueError("If using all scalar values, you must pass an index") ValueError: If using all …

Total answers: 1

Create an edge object without an implicit bias towards a side in Python

Create an edge object without an implicit bias towards a side in Python Question: Python noob here. I am trying to create a network object in Python that contains both node and edge objects. Edges are constructed from two nodes. Networks are constructed from lists of nodes and edges. My problem arises where the network …

Total answers: 1

Annotation with custom types derived from numerical types in Python

Annotation with custom types derived from numerical types in Python Question: I am trying to create a custom type/class in Python that plays well with annotations and also can be checked in runtime. The only way I was able to achieve this is by using TypeAlias. from __future__ import annotations import typing FloatAlias: typing.TypeAlias = …

Total answers: 1

how to print only unique words in a class string

how to print only unique words in a class string Question: this is how I obtained the data input at the beginning: with open("wordslist.txt") as f: words_list = {word.removesuffix("n") for word in f} with open("negation_handling.csv") as g: for tweete in g: for word in tweete.split(): if word not in words_list: print(word) This code resulting in …

Total answers: 1

Sum of items of a class

Sum of items of a class Question: What I have to do is to create a class that counts from a giving single argument and itself make the arithmetical operation. class Counts: def __init__(self, value=0): self.value = value def newvalue(self, other): return Counts(self.value + other) But for every I make to the code I got …

Total answers: 1

How to initialize subclasses of an abstract class?

How to initialize subclasses of an abstract class? Question: I’m trying to create a dark souls style text-based game. I’ve created an abstract class which outlines the characteristics of a dark souls class/character type. There are a couple of ways I have initialized it and I’m not sure if one is better than the other. …

Total answers: 1

In Python how to call Parent class function as if I were Parent object

In Python how to call Parent class function as if I were Parent object Question: I have a Parent and a Child class, both should execute their own fct in init but Child have to execute first the Parent fct : class Parent(object): def __init__(self): self.fct() def fct(self): # do some basic stuff class Child(Parent): …

Total answers: 2

Why does using list(dict_keys()) here, return an empty list?

Why does using list(dict_keys()) here, return an empty list? Question: I am trying to make a Class to represent a Library with a nested class to represent the individual books. class Library: class Book: book_data = {} def __init__(self, title, year, isbn, author): self.title = title self.year = year self.isbn = isbn self.author = author …

Total answers: 1

Python: iterating through class dependants

Python: iterating through class dependants Question: from dataclasses import dataclass @dataclass class BronzeA: name = "bronze_a" quality = "bronze" dependencies = None @dataclass class BronzeAA: name = "bronze_aa" quality = "bronze" dependencies = None @dataclass class SilverAA: name = "silver_aa" quality = "silver" dependencies = [BronzeAA] @dataclass class SilverA: name = "silver_a" quality = "silver" …

Total answers: 1

How do I print class name in a method?

How do I print class name in a method? Question: I made a method and called onto it with super() but I do not know how to write the name of the class in a print statement! from abc import ABC, abstractmethod class Clothing(ABC): @abstractmethod def desc(self): pass class Shirt(Clothing): def desc(self): x = input(‘Enter …

Total answers: 1