I am trying to convert a file to a dictionary here is the contents of the file,
Name: DragonMastur;
Hand: None;
Inventory: {"Gold": 0, "Brush": 0, "Twig": 0, "Sapling": 0, "Metal Axe": 0, "Grass": 0, "Metal Pickaxe": 0, "Metal": 0, "Log": 0, "Diamond": 0, "Stick": 0, "Stone": 0, "Wheat": 0, "Stone Axe": 0, "Stone Pickaxe": 0};
Health: 100;
And here is my code for conversion,
file = open(self.curDir+"/playerstats.txt", "r")
print(file.read().strip().split(";\n"))
print(editor.join(file.read().strip().split(";\n"), ": "))
print(editor.join(file.read().strip().split(";\n"), ": ").split(": "))
self.playerinfo = editor.dictfromlist(editor.join(file.read().strip().split(";\n"), ": ").split(": "))
self.playerinfo["Inventory"] = ast.literal_eval(self.playerinfo["Inventory"].strip().strip(";"))
file.close()
print(self.playerinfo)
The "self.curDir" is the directory with all my files, it opens the file fine but it returns a blank string and/or list after I try to convert it.
And here is the funtion in my custom moudle "editor",
def join(self, list, joiner="\n"):
returnstr = ""
for x in list:
returnstr += str(x) + joiner
returnstr = returnstr[:-int(len(joiner))]
return returnstr
Thanks all help helps.