Problem mit update bei dict

03/12/2012 - 18:30 von Jonel | Report spam
Hallo,
Ich möchte in einen Dictionary zwei Werte updaten.
die normale Ausgabe ist so:

Code:

0, 0
0, 1
0, 2
0, 3
0, 4
1, 1
.
.
.

Wenn ich es ausprinten lasse ist das so, aber ich habe in meinen Dict sind sie nicht so, die Ausgabe ist so:
Code:
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum2.png', 'x': 4}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum3.png', 'x': 0}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum2.png', 'x': 4}

Warum? Ich sehe da keine 1, 1 und so.

Hier ist der Code:

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Generate the playingfield
"""
#~Imports

import cPickle as pickle
import random

#~Define arena

height_rows=5
width_cols=5

#~Define images

grass = {"tile" : "/gametiles/grass.png", "action" : None, "x" : None, "y": None}
baum1 = {"tile" : "/gametiles/baum1.png", "action" : None, "x" : None, "y": None}
baum2 = {"tile" : "/gametiles/baum2.png", "action" : None, "x" : None, "y": None}
baum3 = {"tile" : "/gametiles/baum3.png", "action" : None, "x" : None, "y": None}

#~Variables

row=[]
for y in range(height_rows):
col=[]
for x in range(width_cols):
number = random.randint(1, 10)
if number == 5:
baum1.update({"x" : x, "y" : y})
col.append(baum1)
elif number == 1:
baum2.update({"x" : x, "y" : y})
col.append(baum2)
elif number == 7:
baum3.update({"x" : x, "y" : y})
col.append(baum3)
else:
grass.update({"x" : x, "y" : y})
col.append(grass)
row.append(col)
for i in row:
for i in i:
print i
name = raw_input("mapname: ")
pickle.dump(row, open("../maps/" + name + ".sav", "wb" ) )
print "fertig"
 

Lesen sie die antworten

#1 Sebastian Wiesner
03/12/2012 - 20:10 | Warnen spam
Zwecks Vollstàndigkeit der Link zum entsprechenden Forums-Beitrag:

http://www.python-forum.de/viewtopi...&t0556

Hat ja keinen Sinn, die drei Seiten hier nochmal durchzuackern...

Am 3. Dezember 2012 18:30 schrieb Jonel :
Hallo,
Ich möchte in einen Dictionary zwei Werte updaten.
die normale Ausgabe ist so:

Code:

0, 0
0, 1
0, 2
0, 3
0, 4
1, 1
.
.
.

Wenn ich es ausprinten lasse ist das so, aber ich habe in meinen Dict sind sie nicht so, die Ausgabe ist so:
Code:
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum2.png', 'x': 4}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum3.png', 'x': 0}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum1.png', 'x': 2}
{'action': None, 'y': 4, 'tile': '/gametiles/grass.png', 'x': 3}
{'action': None, 'y': 4, 'tile': '/gametiles/baum2.png', 'x': 4}

Warum? Ich sehe da keine 1, 1 und so.

Hier ist der Code:

Code:
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Generate the playingfield
"""
#~Imports

import cPickle as pickle
import random

#~Define arena

height_rows=5
width_cols=5

#~Define images

grass = {"tile" : "/gametiles/grass.png", "action" : None, "x" : None, "y": None}
baum1 = {"tile" : "/gametiles/baum1.png", "action" : None, "x" : None, "y": None}
baum2 = {"tile" : "/gametiles/baum2.png", "action" : None, "x" : None, "y": None}
baum3 = {"tile" : "/gametiles/baum3.png", "action" : None, "x" : None, "y": None}

#~Variables

row=[]
for y in range(height_rows):
col=[]
for x in range(width_cols):
number = random.randint(1, 10)
if number == 5:
baum1.update({"x" : x, "y" : y})
col.append(baum1)
elif number == 1:
baum2.update({"x" : x, "y" : y})
col.append(baum2)
elif number == 7:
baum3.update({"x" : x, "y" : y})
col.append(baum3)
else:
grass.update({"x" : x, "y" : y})
col.append(grass)
row.append(col)
for i in row:
for i in i:
print i
name = raw_input("mapname: ")
pickle.dump(row, open("../maps/" + name + ".sav", "wb" ) )
print "fertig"
_______________________________________________
python-de maillist -
http://mail.python.org/mailman/listinfo/python-de

Ähnliche fragen