June 2017
Beginner
352 pages
8h 39m
English
Let's add a second function, string_log() to our module, which calls our convert() function and computes the natural log of the result:
from math import logdef string_log(s): v = convert(s) return log(v)
At this point we must confess that we've gone out of our way here to be deeply unPythonic by wrapping the perfectly good int() conversion, which raises exceptions on failure, in our convert() function which returns a good old-fashioned negative error code. Rest assured that this unforgivable Python heresy has been committed solely to demonstrate the greatest folly of error return codes: That they can be ignored by the caller, wreaking havoc amongst unsuspecting code later in the program. A slightly better program might ...
Read now
Unlock full access