ATIX20

Page 53

import itertools # Intenta ocasionar un MemoryError allocando un mont贸n de memoria l = [] for i in range(3): try: for j in itertools.count(1): print i, j l.append('*' * (2**30)) except MemoryError: print '(error, descartando lista existente)' l = [] $ python exceptions_MemoryError.py python(49670) malloc: *** mmap(size=1073745920) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug python(49670) malloc: *** mmap(size=1073745920) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug python(49670) malloc: *** mmap(size=1073745920) failed (error code=12) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug 0 1 0 2 0 3 (error, descartando lista existente) 1 1 1 2 1 3 (error, descartando lista existente) 2 1 2 2 2 3 (error, descartando lista existente)

NameError NameErrors se producen cuando tu c贸digo hace referencia a un nombre que no existe en el

谩mbito actual. Por ejemplo, un nombre de variable no calificado. def func(): print nombre_desconocido func() $ python exceptions_NameError.py Traceback (most recent call last): File "exceptions_NameError.py", line 15, in <module> func() File "exceptions_NameError.py", line 13, in func print nombre_desconocido NameError: global name 'nombre_desconocido' is not defined

NotImplementedError Clases base definidas por el usuario pueden producir NotImplementedError para indicar que un m茅todo o funcionamiento necesitan ser definidos por una sub clase, simulando una interfaz.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.