attributes

How to create conditional instance attribute in python which can only take value >= 5000,else prompt user that minimum is 5000?

How to create conditional instance attribute in python which can only take value >= 5000,else prompt user that minimum is 5000? Question: I have class ‘Player’ in python and wanna create instance attribute ‘deposit’,which intended take integer equal or greather 5000,else raise error or to ask user set valid value.So I tried implement that with …

Total answers: 1

Simple problem with Class RandomEvent in Python

Simple problem with Class RandomEvent in Python Question: I create a simple text quest with random events, which accumulated a lot, and I decided to separate them into a separate class. But after that I got a problem. It doesn’t look complicated, but I can’t find a solution. import random class Hero: def __init__(self, name): …

Total answers: 1

Adding attributes with ascending integer values to XML elements

Adding attributes with ascending integer values to XML elements Question: I want to add the add attribute ‘id="number"’ to an existing file. But the number should be ascending in the way they are added. So right now my XML file looks like this: <Invoice> <Fussteil> <Summen> <QF/> <UstSatz>21.00</UstSatz> <Betrag> <Bezeichnung>Steuerbetrag</Bezeichnung> <QF>124</QF> <Wert>8.8</Wert> </Betrag> <Betrag> <Bezeichnung>steuerpflichtiger …

Total answers: 1

scrape a sub attribute? with bs4 in python

scrape a sub attribute? with bs4 in python Question: I’m trying to scrape the id’s on a website, but I can’t figure out how to specify the entry I want to work with. this is the most I could narrow it down to a specific class, but I’m not sure how to target the number …

Total answers: 1

How can I update an attribute that's added to a method via a decorator?

How can I update an attribute that's added to a method via a decorator? Question: I’ve created a decorator that wraps tkinter’s after() method to make looping functions easier (i.e., having a function call itself periodically) import tkinter as tk from functools import wraps # decorator def after_loop(interval: int): """Loop the decorated method at the …

Total answers: 1

create a list of an objectA inside the objectA

create a list of an objectA inside the objectA Question: When I’m trying to append() the object itself into a list inside the object, it doesn’t work, I don’t understand why. class PLayer: CLASS_NAME = "player" TOTAL_PLAYER_NUMBER = 0 TOTAL_PLAYER_LIST = [] PLAYER_ID_INCREMENT = 0 def __init__(self, name, first_name, birthday, note, player_id=None, total_score=None, tournament_score=None): self.PLAYER_ID_INCREMENT …

Total answers: 1

I keep getting an attribute error is this

I keep getting an attribute error is this Question: Create a class called Point. The point should have two attributes: Attribute Name Description x x-coordinate of the point y y-cordinate of the point You should override the init(), str(), add(), sub() and mul() methods but my add sub and mul methods keep getting an attribute …

Total answers: 1

Object has no attribute error when I name attribute with double underscores

Object has no attribute error when I name attribute with double underscores Question: I am trying to group all Patient objects by their surnames. My code: class Patient: def __init__(self, first_name, surname, age, mobile, postcode): self.__first_name = first_name self.__surname = surname self.__doctor = "None" self.__age = age self.__mobile = mobile self.__postcode = postcode self.__symptoms = …

Total answers: 1

How to retrieve an attribute from a list of instances properly

How to retrieve an attribute from a list of instances properly Question: I am unsure how to correctly get the attribute from a list of instances. Sorry if this seems simple, I am only a beginner. class Clown: def __init__(self,name,hours,job): self.name = name self.hours = hours self.job = job def get_job(self): return self.job def change_job(self, …

Total answers: 1

'float' object has no attribute 'insert'

'float' object has no attribute 'insert' Question: a = [5, -2.5, 3, 4, 12, 17] v = [] b = 0 c = 1 for i in a: if i>0: b = b + 1 print(i, end=" ") elif i<0: v.insert(i) print(v.sum()) i.insert(v) AttributeError: ‘float’ object has no attribute ‘insert’                                 . Asked By: g0lnad || …

Total answers: 1