in der folgenden Funktion, was macht try:
früh verlassen? Wenn ich den gleichen Code außerhalb eines def
Blocks setze, funktioniert es gut.was macht versuchen: früh verlassen?
tiles = ['095D', '094M']
in_file = 'in_file'
out_file = 'out_file'
expression = ''' "FIELDNAME" LIKE 'STUFF' '''
def foobar(in_file, out_file, expression):
print in_file, out_file, expression
try:
print 'this is trying'
#pretty print tile list, from http://stackoverflow.com/questions/2399112/python-print-delimited-list
tiles = ','.join(map(str,tiles))
print 'made it past tiles!'
print 'From %s \nselecting %s \ninto %s' % (in_file, tiles, out_file)
except:
print 'Made it to the except block!'
foobar(in_file, out_file, expression)
Ergebnisse:
D:\> python xx-debug.py
in_file out_file "FIELDNAME" LIKE 'STUFF'
this is trying
Made it to the except block!
Ergebnisse mit den same code not in a def:
this is trying
made it past tiles!
From in_file
selecting 095D,094M
into out_file
einfach dort, Anfänger werden solche Dinge tun. –
@aaronasterling "Pokemon Exception Handling - Ich muss sie alle fangen!" –
Sie sollten nicht 'außer:' ohne Angabe einer Ausnahme. Das fängt auch Dinge wie KeyboardInterrupt ein, die fast nie das sind, was Sie wollen. – ThiefMaster