I'm a beginner using python 3.2 and i have a book whos code is all in python 2.6. i wrote part of a program and keep getting: Syntax Error: invalid syntax Then python's IDLE highlights the comma after KeyError in my code:
from tank import Tank
tanks = { "a":Tank("Alice"), "b":Tank("Bob"), "c":Tank("Carol")}
alive_tanks = len(tanks)
while alive_tanks > 1:
print
for tank_name in sorted( tanks.keys() ):
print (tank_name, tanks[tank_name])
first = raw_input("Who fires? ").lower()
second = raw_input("Who at? ").lower()
try:
first_tank = tanks[first]
second_tank = tanks[second]
except KeyError, name:
print ("No such tank exists!", name)
continue
Instead of
except KeyError, name:
try
except KeyError as name:
Its a difference between Python 2.x and Python 3.x. The first form is no longer supported.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With