Python: How to store class object ref in txt file as part of another class objects attributes, for use with importing to populate class object -
i'm building game in python. in have class called actor.
class actor: def __init__(self, *initial_data, **kwargs): self.name = 0 self.weapon = 0 ...#other attributes #this code lets populate class attributes using dictionary dictionary in initial_data: key in dictionary: setattr(self, key, dictionary[key]) key in kwargs: setattr(self, key, kwargs[key]) i using code in function populate class when call func. "source" path directory provide function.
with open(source) char_data: char_stats = dict(filter(none, csv.reader(char_data))) # load in passed in data dummy text file "source" in place of mysql database dictionary character = actor(char_stats) # dump dictionary character class return character # return filled out character class i using simple txt file file store attribute data
name,bob health,100 stamina,100 magic,100 weight,100 ... weapon,sword() #i want doesn't work out for i'm using txt file in place of database until bugs out. there way this? have class called sword() defined. there way turn string sword() class object sword()? there way store text file when imported python interprets class sword , not str"sword()"?
Comments
Post a Comment