0
how to call a parameter from the def init method in @staticmethod ?
def calc(self): pass @classmethod def update(cls): cls.calc() TypeError: calc() missing 1 required positional argument: 'self'
6 Respuestas
+ 2
Is that the complete code? Shouldn't there be a class?
(and a static method is not the same as a class method)
+ 1
Something like this ?
class Student():
def __init__(self,n,a):
self.name=n
self.age=a
@staticmethod
def About_me(obj):
print(f"My name is {a.name}")
a=Student("xyz",100)
Student.About_me(a)
0
no, this is not the full code. the full code is too large, but this is the essence of the error
0
Full code:
import random
import os
import json
class Basic_params:
class_object = f'{name}.json'
def init(self):
self.temp = {}
self.params = {
'name': 'name',
'basic_params': {
'basic_strength': 0,
'basic_agility': 0,
'basic_intelligence': 0,
'basic_stamina': 0,
'basic_damage': 0,
'basic_armor': 0,
'basic_crit': 0,
'basic_chance_crit': 0,
'basic_magic_damage': 0,
'basic_hp': 0,
'basic_mana': 0,
'basic_hp_regen': 0,
'basic_mana_regen': 0,
'basic_move_speed': 0,
'basic_magic_resist': 0,
'basic_attack_speed': 0,
'basic_chance_dodge': 0,
'basic_luck': 0
}
}
self.temp0 = {}
self.temp0.update({'0': self.params})
self.my_id = self.get_nex
0
from Basic_params import Basic_params
import json
import random
class Atrribut(Basic_params):
def init(self):
super().init()
self.bp = self.params['basic_params']
self.atrribut = {}
def calc(self):
self.atrribut = {
'hp': {
'max_hp': int(self.bp['basic_hp']) + int(self.bp['basic_stamina']) * 10,
'current_hp': int(self.bp['basic_hp']) + int(self.bp['basic_stamina']) * 10,
'regen_hp': int(self.bp['basic_hp_regen']) + int(self.bp['basic_stamina']) / 10
},
'mana': {
'max_mana': int(self.bp['basic_mana']) + int(self.bp['basic_intelligence']) * 10,
'current_mana': int(self.bp['basic_mana']) + int(self.bp['basic_intelligence']) * 10,
'current_regen_mana': int(self.bp['basic_mana_regen']) + int(self.bp['basic_intelligence']) / 10
},
'damage': {
'current_damage': int(self.bp['basic_damage']) + int(self.bp[
0
thank you but I have already rewritten the code