Ich bin ein totaler Noob zu Python und brauche etwas Hilfe mit meinem Code. Der Code soll Input.txt [http://pastebin.com/bMdjrqFE] übernehmen, in separate Pokemon (in einer Liste) aufteilen und dann in separate Werte aufteilen, die ich benutze, um die Daten neu zu formatieren und in Output.txt zu schreiben.Der gleiche Wert in der Liste wird immer wieder beim Schreiben in Textdatei
Allerdings, wenn ich das Programm ausführen, wird nur das letzte Pokemon ausgegeben, 386 mal. [http://pastebin.com/wkHzvvgE]
Hier ist mein Code:
f = open("Input.txt", "r")#opens the file (input.txt)
nf = open("Output.txt", "w")#opens the file (output.txt)
pokeData = []
for line in f:
#print "%r" % line
pokeData.append(line)
num = 0
tab = """ """
newl = """NEWL
"""
slash = "/"
while num != 386:
current = pokeData
current.append(line)
print current[num]
for tab in current:
words = tab.split()
print words
for newl in words:
nf.write('%s:{num:%s,species:"%s",types:["%s","%s"],baseStats:{hp:%s,atk:%s,def:%s,spa:%s,spd:%s,spe:%s},abilities:{0:"%s"},{1:"%s"},heightm:%s,weightkg:%s,color:"Who cares",eggGroups:["%s"],["%s"]},\n' % (str(words[2]).lower(),str(words[1]),str(words[2]),str(words[3]),str(words[4]),str(words[5]),str(words[6]),str(words[7]),str(words[8]),str(words[9]),str(words[10]),str(words[12]).replace("_"," "),str(words[12]),str(words[14]),str(words[15]),str(words[16]),str(words[16])))
num = num + 1
nf.close()
f.close()
Vielen Dank! Dank dir konnte ich es herausfinden. –