howeveran alternative way to handle errors is to simply let the program generate an exception and to catch it for exampledef parse_header(line)fields line split(":"tryheadervalue fields return header lower()value strip(except valueerrorraise runtimeerror("malformed header"if you benchmark both versions on properly formatted linethe second version of code runs about percent faster setting up try block for code that normally doesn' raise an exceptions runs more quickly than executing an if statement avoid exceptions for common cases don' write code that uses exception handling for the common case for examplesuppose you had program that performed lot of dictionary lookupsbut most of these lookups were for keys that didn' exist nowconsider two approaches to performing lookupapproach perform lookup and catch an exception tryvalue items[keyexcept keyerrorvalue none approach check if the key exists and perform lookup if key in itemsvalue items[keyelsevalue none in simple performance measurement where the key is not foundthe second approach runs more than times fasterin case you were wonderingthis latter approach also runs almost twice as fast as using items get(keybecause the in operator is faster to execute than method call embrace functional programming and iteration list comprehensionsgenerator expressionsgeneratorscoroutinesand closures are much more efficient than most python programmers realize for data processing especiallylist comprehensions and generator expressions run significantly more quickly than code that manually iterates over data and carries out similar operations these operations also run much more quickly than legacy python code that uses functions such as map(and filter(generators can be used to write code that not only runs fastbut which makes efficient use of memory use decorators and metaclasses decorators and metaclasses are features that are used to modify functions and classes howeverbecause they operate at the time of function or class definitionthey can be used in ways that lead to improved performance--especially if program has many optional features that might be turned on or off "functions and functional programming,has an example of using decorator to enable logging of functionsbut in way that does not impact performance when logging is disabled lib fl ff